运行MSBuild在csproj上不适用于web.config转换。

4
我正在使用Team City处理我们的部署。因此,我创建了一个MSBuild步骤来编译我们的.sln文件。构建后,输出目录中有以下三个文件:
- Web.config - Web.Release.config - Web.Debug.config
这意味着MSBuild任务不会转换web.config文件。但是,当我在Visual Studio中使用发布功能时,转换就会完成。那么,MSBuild和发布之间有什么区别?如何强制执行MSBuild任务以转换配置?

我不确定我是否理解您所说的“不转换web.config”的意思? - Arun
在我的输出目录中,我只有3个web.config.*文件,我希望只有一个应用了转换的web.config文件。 - remi bourgarel
1个回答

1

我在这里找到了答案

https://github.com/geersch/TeamCity/blob/master/src/part-3/README.md

这是我的任务:

<Target Name="Publish">    
   <RemoveDir Directories="$(DestinationPath)" ContinueOnError="true" />         
   <MSBuild Projects="$(SourcePath)/$(ProjectFile)" Targets="Rebuild;ResolveReferences;_CopyWebApplication" Properties="WebProjectOutputDir=$(DestinationPath);OutDir=$(DestinationPath)\bin\" />  

   <TransformXml Source="$(SourcePath)/Web.Config" Transform="$(SourcePath)/Web.$(Configuration).config" Destination="$(DestinationPath)/Web.config" />
   <ItemGroup>
      <FilesToDelete Include="$(DestinationPath)/Web.*.config"/>
   </ItemGroup>
   <Delete Files="@(FilesToDelete)"/>
</Target>

你可以像这样调用它

 <MSBuild Projects="$(MSBuildProjectFullPath)" 
         Targets="Publish" 
         Properties="Configuration=Release;ProjectFile=WebProject.csproj;SourcePath=C:\webproject\;DestinationPath=C:\inetpub\wwwroot\app\"/>

谢谢


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接