我有以下任务:
<!--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参数中缺少一些设置,但我无法在文档中找到任何表明此类的设置。
答案 0 :(得分:2)
aspnet_compiler可以使用web.config值来区分调试和'零售'编译之间的区别,但条件通常作为参数传递给编译器(参见this),无论是什么驱动构建(例如Visual Studio,NAnt或其他)。 ASP编译器没有,所以你需要将它们包含在web.config文件的codedom
部分中:
<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中切换其他调试标志时也要更改它。