Asp.net
MSBuild Script 和 VS2010 發布應用 Web.config 轉換
因此,我安裝了 VS 2010,並且正在修改我的 MSBuild 腳本以進行 TeamCity 建構集成。除了一個例外,一切都很好。
我如何告訴 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>我已經測試了上述內容,並且可以確認它有效。您可能需要稍微調整結構以更好地適應您的建構腳本。