【问题标题】:Run MSBuild on a csproj doesn't apply web.config transofmration在 csproj 上运行 MSBuild 不会应用 web.config 转换
【发布时间】:2011-11-03 17:35:06
【问题描述】:

我正在使用 Team City 来处理我们的部署。

所以我创建了一个 MSBuild 步骤来编译我们的 .sln 文件。

构建后,我的输出目录中有这三个文件:

  • Web.config
  • Web.Release.config
  • Web.Debug.config

这意味着 msbuild 任务不会转换 web.config。

但是当我在 Visual Studio 中使用发布功能时,转换就完成了。

那么,msbuild 和 publish 有什么区别?以及如何强制我的 msbuild 任务转换配置?

【问题讨论】:

  • 我不确定我是否理解您所说的“不转换 web.config”是什么意思?
  • 在我的输出目录中,我只有 3 个 web.config.* 文件,我希望只有 1 个 web.config 应用了转换

标签: msbuild web-config


【解决方案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\"/>

谢谢

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-04-10
    • 2012-02-17
    • 2022-02-19
    • 1970-01-01
    • 2014-05-08
    • 2023-04-04
    • 2013-07-15
    相关资源
    最近更新 更多