<bdo id='njTym'></bdo><ul id='njTym'></ul>
<tfoot id='njTym'></tfoot>
  • <small id='njTym'></small><noframes id='njTym'>

      <legend id='njTym'><style id='njTym'><dir id='njTym'><q id='njTym'></q></dir></style></legend>
      <i id='njTym'><tr id='njTym'><dt id='njTym'><q id='njTym'><span id='njTym'><b id='njTym'><form id='njTym'><ins id='njTym'></ins><ul id='njTym'></ul><sub id='njTym'></sub></form><legend id='njTym'></legend><bdo id='njTym'><pre id='njTym'><center id='njTym'></center></pre></bdo></b><th id='njTym'></th></span></q></dt></tr></i><div id='njTym'><tfoot id='njTym'></tfoot><dl id='njTym'><fieldset id='njTym'></fieldset></dl></div>

      1. 我可以从 csharp 中的编译时环境变量中创建一个常量吗?

        时间:2023-09-13
        • <bdo id='lelAx'></bdo><ul id='lelAx'></ul>

              <legend id='lelAx'><style id='lelAx'><dir id='lelAx'><q id='lelAx'></q></dir></style></legend>
              <tfoot id='lelAx'></tfoot>

                  <tbody id='lelAx'></tbody>

                <small id='lelAx'></small><noframes id='lelAx'>

                  <i id='lelAx'><tr id='lelAx'><dt id='lelAx'><q id='lelAx'><span id='lelAx'><b id='lelAx'><form id='lelAx'><ins id='lelAx'></ins><ul id='lelAx'></ul><sub id='lelAx'></sub></form><legend id='lelAx'></legend><bdo id='lelAx'><pre id='lelAx'><center id='lelAx'></center></pre></bdo></b><th id='lelAx'></th></span></q></dt></tr></i><div id='lelAx'><tfoot id='lelAx'></tfoot><dl id='lelAx'><fieldset id='lelAx'></fieldset></dl></div>
                  本文介绍了我可以从 csharp 中的编译时环境变量中创建一个常量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我们使用 Hudson 来构建我们的项目,并且 Hudson 可以方便地定义环境变量,例如%BUILD_NUMBER%"编译时间.

                  We use Hudson to build our projects, and Hudson conveniently defines environment variables like "%BUILD_NUMBER%" at compile time.

                  我想在代码中使用该变量,这样我们就可以在运行时记录下构建的内容.但是我不能做 System.Environment.GetEnvironmentVariable 因为那是访问运行时环境,我想要的是这样的:

                  I'd like to use that variable in code, so we can do things like log what build this is at run time. However I CAN NOT do System.Environment.GetEnvironmentVariable because that is accessing the run-time environment, what I want is something like:

                  #define BUILD_NUM = %BUILD_NUMBER%
                  

                  const string BUILD_NUM = %BUILD_NUMBER%
                  

                  除非我不知道语法.有人可以指出我正确的方向吗?谢谢!

                  Except I don't know the syntax. Can someone please point me in the right direction? Thanks!

                  推荐答案

                  好的,这就是我最终要做的.它不是很优雅,但它确实有效.我创建了一个如下所示的预构建步骤:

                  Okay here's what I wound up doing. It's not very elegant, but it works. I created a pre-build step that looks like this:

                  echo namespace Some.Namespace > "$(ProjectDir)CiInfo.cs"
                  echo { >> "$(ProjectDir)CiInfo.cs"
                  echo     ///^<summary^>Info about the continuous integration server build that produced this binary.^</summary^> >> "$(ProjectDir)CiInfo.cs"
                  echo     public static class CiInfo >> "$(ProjectDir)CiInfo.cs"
                  echo     { >> "$(ProjectDir)CiInfo.cs"
                  echo         ///^<summary^>The current build number, such as "153"^</summary^> >> "$(ProjectDir)CiInfo.cs"
                  echo         public const string BuildNumber = ("%BUILD_NUMBER%" == "" ? @"Unknown" : "%BUILD_NUMBER%"); >> "$(ProjectDir)CiInfo.cs"
                  echo         ///^<summary^>String of the build number and build date/time, and other useful info.^</summary^> >> "$(ProjectDir)CiInfo.cs"
                  echo         public const string BuildTag = ("%BUILD_TAG%" == "" ? @"nohudson" : "%BUILD_TAG%") + " built: %DATE%-%TIME%"; >> "$(ProjectDir)CiInfo.cs"
                  echo     } >> "$(ProjectDir)CiInfo.cs"
                  echo } >> "$(ProjectDir)CiInfo.cs"
                  

                  然后我将CiInfo.cs"添加到项目中,但从版本控制中忽略了它.这样我就不必编辑或提交它,并且该项目始终有一个可用的常量,即最新的内部版本号和时间.

                  Then I added "CiInfo.cs" to the project, but ignored it from version control. That way I never have to edit it or commit it, and the project always has a constant available that is the latest build number and time.

                  这篇关于我可以从 csharp 中的编译时环境变量中创建一个常量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:什么决定了 Path.GetTempPath() 的返回值? 下一篇:如何在 Visual Studio 2010 中设置环境变量?

                  相关文章

                  1. <legend id='76C0k'><style id='76C0k'><dir id='76C0k'><q id='76C0k'></q></dir></style></legend>

                    <tfoot id='76C0k'></tfoot>

                        <bdo id='76C0k'></bdo><ul id='76C0k'></ul>
                    1. <i id='76C0k'><tr id='76C0k'><dt id='76C0k'><q id='76C0k'><span id='76C0k'><b id='76C0k'><form id='76C0k'><ins id='76C0k'></ins><ul id='76C0k'></ul><sub id='76C0k'></sub></form><legend id='76C0k'></legend><bdo id='76C0k'><pre id='76C0k'><center id='76C0k'></center></pre></bdo></b><th id='76C0k'></th></span></q></dt></tr></i><div id='76C0k'><tfoot id='76C0k'></tfoot><dl id='76C0k'><fieldset id='76C0k'></fieldset></dl></div>
                    2. <small id='76C0k'></small><noframes id='76C0k'>