无法使用msbuild webconfig转换设置配置和平台

时间:2013-07-08 13:10:44

标签: msbuild msbuild-task msbuildcommunitytasks

我正在使用msuild并尝试通过msbuild脚本实现web.config转换。我添加了额外的web.staging.config和web.production.config。当我尝试使用命令行运行目标时 msbuild tweb.xml / t:tw / p:Configuration = staging; Platform = AnyCPU

低于error.pls帮助我,我在做什么错误???

"E:\tweb.xml" (tw target) (1) ->
(_CheckForInvalidConfigurationAndPlatform target) ->
  C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(483,9)
: error : The OutputPath property is not set for project 'tweb.xml'.  Please ch
eck to make sure that you have specified a valid combination of Configuration a
nd Platform for this project.  Configuration='staging'  Platform='AnyCPU'.  You
 may be seeing this message because you are trying to build a project without a
 solution file, and have specified a non-default Configuration or Platform that
 doesn't exist for this project. [E:\tweb.xml]

0 Warning(s)
1 Error(s)

以下是我的代码

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>

  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'staging|AnyCPU'">
    <WebConfigReplacement>staging</WebConfigReplacement>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'production|AnyCPU'">
    <WebConfigReplacement>production</WebConfigReplacement>
  </PropertyGroup>





  <PropertyGroup>
    <TransformInputFile>D:\webTransdemo\deploye\Web.Temp.config</TransformInputFile>
    <TransformFile>D:\webTransdemo\WebTransform\WebTransform\Web.$(WebConfigReplacement).config</TransformFile>
    <TransformOutputFile>D:\webTransdemo\WebTransform\WebTransform\Web.config</TransformOutputFile>
    <StackTraceEnabled>False</StackTraceEnabled>
  </PropertyGroup>

  <ItemGroup>
    <OriginalWebConfig Include="D:\webTransdemo\WebTransform\WebTransform\Web.config"/>
    <TempWebConfig Include="D:\webTransdemo\deploye\Web.Temp.config"/>
  </ItemGroup>


  <Target Name="tw"  Condition="'$(Configuration)|$(Platform)' == 'Production|AnyCPU' Or '$(Configuration)|$(Platform)' == 'Staging|AnyCPU'">

    <Copy SourceFiles="@(OriginalWebConfig)" DestinationFiles="@(TempWebConfig)" />

    <TransformXml               Source="$(TransformInputFile)"   
                                Destination="$(TransformOutputFile)"
                                Transform="$(TransformFile)"
                                StackTrace="$(StackTraceEnabled)" />
    <Delete Files="@(TempWebConfig)"/>


  </Target>

1 个答案:

答案 0 :(得分:0)

您需要设置OutputPath属性。

<OutputPath>bin\</OutputPath>

此外,您的目标将不会被执行,因为配置与您传入的参数不匹配。确保外壳匹配 -

<Target Name="tw"  Condition="'$(Configuration)|$(Platform)' == 'production|AnyCPU' Or '$(Configuration)|$(Platform)' == 'staging|AnyCPU'">