在解决方案文件上调用TransformWebConfig

Jas*_*inn 3 msbuild visual-studio-2010

我有一个包含多个项目的解决方案,其中一个项目是一个Web应用程序,我希望能够在使用MSBuild构建解决方案时使用web.release.config转换web.config.我打电话的时候

MSBuild"WebProject.csproj"/ t:TransformWebConfig/p:Configuration = Release

在web项目中,我将转换后的web.config输出转换为...\_对象\ Release\TransformWebConfig\transformed\Web.config

但是当我试着打电话的时候

MSBuild"Solution.sln"/ t:TransformWebConfig/p:Configuration = Release

我收到错误"项目中不存在TransformWebConfig".你有没有让它工作,所以它会输出一个转换后的web.config,如果可能的话,忽略命令的TransformWebConfig部分?

Jas*_*inn 5

最简单的方法是将Web项目.csproj文件更改为

<Project ToolsVersion="4.0" DefaultTargets="BuildWithConfig" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
Run Code Online (Sandbox Code Playgroud)

然后添加一个新目标

<Target Name="BuildWithConfig">
    <CallTarget Targets="Build"/>
    <CallTarget Targets="TransformWebConfig"/>
</Target>
Run Code Online (Sandbox Code Playgroud)

然后运行

MSBuild"Solution.sln"/ p:Configuration = Release

该文件将输出到...\WebProject\obj\Release\TransformWebConfig\transformed