2011-03-11 104 views
2

我有以下恶性任务:南特aspnet_compiler.exe发布版本

<!--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文件)作为查询字符串参数追加,并确保在调试缓存版本时未收到,但一旦发布即可管理。

但是,在我认为应该编译一个relase构建之后,该版本仍然被设置为Guid,表示我还没有实现发布版本。我检查了web.config,并将debug的值更改为false,因此我假设我在aspnet_compiler.exe参数中缺少了一些设置,但我无法在文档中找到任何指示这样的设置。

回答

2

aspnet_compiler可以使用web.config的值来区分调试和“零售”编译,但条件通常作为参数传递给编译器(请参阅this),无论驱动构建如何(例如Visual工作室,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提供你所需要的#调试定义。当由aspnet_compiler调用时,编译器本身会收到它,并且应该反映在代码中的#conditional块中。所以记得在你的web.config中切换另一个调试标志时也要改变它。

+0

感谢您的回答,我通过使用msbuild和/ d:Release参数来调用构建作为上一步到asp编译器的工作来解决这个问题。 从你的答案我asuming aspnet编译器调用csharp编译器卸载构建并使用web.config来寻找这样的参数? – DannyT 2011-03-11 17:18:58

+0

正确,就是这样。 – kprobst 2011-03-11 17:20:31