msbuild脚本和VS2010发布apply web.config变换
-
04-10-2019 - |
题
因此,我已经安装了VS 2010,并且正在修改我的MSBUILD脚本以进行团队构建集成。一切都很好,一个例外。
我如何告诉MSBuild我要应用我在发布构建时创建的Web.conifg变换文件...
我有以下内容生成编译的网站,但是,它输出一个web.config,web.debug.config和web.release.config文件(全3)到编译的输出目录。在Studio中,当我执行发布到文件系统时,它将进行转换,并且仅输出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>
我已经测试了上述内容,并可以确认它有效。您可能需要对结构进行一些调整以更好地适合您的构建脚本。
其他提示
您应该能够通过使用软件包目标并指定临时目录来实现这一目标。
msbuild solution.sln /p:Configuration=Release;DeployOnBuild=true;DeployTarget=Package;_PackageTempDir=..\publish
它对我有用以下更改工作
<MSBuild Projects="$(ProjectFile)"
Targets="ResolveReferences;_WPPCopyWebApplication"
Properties="WebProjectOutputDir=TempOutputFolder;OutDir=$(WebProjectOutputDir);Configuration=$(Configuration);" />
来自microsoft.webapplication.targets文件,下面是msbuild文件夹
_CopyWebApplication
This target will copy the build outputs along with the
content files into a _PublishedWebsites folder.
This Task is only necessary when $(OutDir) has been redirected
to a folder other than ~\bin such as is the case with Team Build.
The original _CopyWebApplication is now a Legacy, you can still use it by
setting $(UseWPP_CopyWebApplication) to true.
By default, it now change to use _WPPCopyWebApplication target in
Microsoft.Web.Publish.targets.
It allow to leverage the web.config trsnaformation.
我不是MSBuild的专家,但是我能够使用此链接中的信息来完成相同的任务:
文章底部附近有一个与MSBUILD有关的部分。希望这可以帮助。
在我解决这个问题之前,我一直在搜索几天后,对此话题的另一个答案:
您的发布配置文件和配置名称应匹配。
就我而言,我没有。通过发布个人资料手动发布给了我所需的结果,因为我的配置是在发布配置文件中设置的。但是,MSBUILD试图智能,并根据名称神奇地连接发布配置文件和配置。 (在命令中添加 /p:配置导致有关引用项目的输出路径的其他奇怪错误)。
只是要清楚我的意思:
命令行的msbuild语句
msbuild myproject.csproj -t:clean -t:recuild /p:deployonbuild = true /p:publishProfile =“开发”
作品
- 发布个人资料名称: : 发展
- 解决方案配置名称: : 发展
不起作用
- 发布个人资料名称: : 发展
- 解决方案配置名称: :dev
希望这可以帮助!