因此,我安装了 VS 2010,并且正在为我们的 TeamCity 构建集成修改我的 MSBuild 脚本。一切正常,只有一个异常(exception)。
如何告诉 MSBuild 我想应用我在发布构建时创建的 Web.conifg 转换文件...
我有以下生成已编译网站的内容,但它会将 Web.config、Web.Debug.config 和 Web.Release.config 文件(全部 3 个)输出到已编译的输出目录。在工作室中,当我执行发布到文件系统时,它将进行转换并仅输出具有适当更改的 Web.config...
<Target Name="CompileWeb">
<MSBuild Projects="myproj.csproj" Properties="Configuration=Release;" />
</Target>
<Target Name="PublishWeb" DependsOnTargets="CompileWeb">
<MSBuild Projects="myproj.csproj"
Targets="ResolveReferences;_CopyWebApplication"
Properties="WebProjectOutputDir=$(OutputFolder)$(WebOutputFolder);
OutDir=$(TempOutputFolder)$(WebOutputFolder)\;Configuration=Release;" />
</Target>
任何帮助都会很棒..!
我知道这可以通过其他方式完成,但我想尽可能使用新的 VS 2010 方式来完成此操作
最佳答案
我一直在寻找类似的信息,但没有完全找到,所以我在 Visual Studio 2010 和 MSBuild 4.0 附带的 .targets 文件中进行了一些挖掘。我认为这是寻找执行转换的 MSBuild 任务的最佳位置。
据我所知,使用了以下 MSBuild 任务:
<Project ToolsVersion="4.0"
DefaultTargets="Deploy"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
<PropertyGroup>
<ProjectPath>C:\Path to Project\Here</ProjectPath>
<DeployPath>C:\Path to Deploy\There</DeployPath>
<TransformInputFile>$(ProjectPath)\Web.config</TransformInputFile>
<TransformFile>$(ProjectPath)\Web.$(Configuration).config</TransformFile>
<TransformOutputFile>$(DeployPath)\Web.config</TransformOutputFile>
<StackTraceEnabled>False</StackTraceEnabled>
</PropertyGroup>
<Target Name="Transform">
<TransformXml Source="$(TransformInputFile)"
Transform="$(TransformFile)"
Destination="$(TransformOutputFile)"
Condition="some condition here"
StackTrace="$(StackTraceEnabled)" />
</Target>
</Project>
我已经测试了上面的内容,可以确认它是有效的。您可能需要稍微调整结构以更好地适应您的构建脚本。
关于asp.net - MSBuild 脚本和 VS2010 发布应用 Web.config 转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2905151/