2

我有以下任务:

<!--Compiles the possible release candidate to be used for further testing and possible release -->
<target name="createReleaseCandidateJob">
  <xmlpoke file="${nant.project.basedir}/${webApplicationProjectName}/Web.config"
   xpath="/configuration/system.web/compilation/@debug"
   value="false" />
  <exec basedir="." program="C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe"
        commandline="-p ${webApplicationProjectName} -v / ${releaseCandidateOutputDir}"
        workingdir="."
        failonerror="true"
      />
  <echo>Completed Compile RC Job</echo>
</target>

我的项目中还包含以下代码行:

myVersion = "2.0b";
#if DEBUG
     myVersion = Guid.NewId().ToString();
#endif

这在加载某些资产(swf 文件)时通过附加为查询字符串参数来使用,并确保在调试缓存版本时不会收到缓存版本,但一旦发布就可以管理。

但是,在我认为应该编译发布版本之后,该版本仍被设置为 Guid,表明我还没有实现发布版本。我检查了 web.config 并且 debug 的值更改为 false 所以我假设我在 aspnet_compiler.exe 参数中缺少一些设置,但我在文档中找不到任何表明这样的内容。

4

1 回答 1

2

aspnet_compiler 可以使用 web.config 值来区分调试和“零售”编译之间的区别,但条件通常作为参数传递给编译器(见这个),由驱动构建的任何东西(例如 Visual Studio、NAnt 或任何)。ASP 编译器没有,因此您需要将它们包含在codedomweb.config 文件的部分中:

<system.codedom>
  <compilers>
    <compiler
      language="c#;cs;csharp" 
      extension=".cs"
      warningLevel="4"
      compilerOptions="/d:DEBUG"
      type="Microsoft.CSharp.CSharpCodeProvider, 
        System, Version=2.0.0.0, Culture=neutral, 
        PublicKeyToken=b77a5c561934e089" />
    </compilers>
</system.codedom>

在这里,compilerOptions提供了您需要的#DEBUG 定义。这将在 aspnet_compiler 调用时由编译器本身拾取,并且应该反映在代码中的 #conditional 块中。因此,请记住在您切换 web.config 中的其他调试标志时也要更改它。

于 2011-03-11T16:51:38.197 回答