首页 文章

MSBuild条件阻止app.config XML转换

提问于
浏览
1

我正在使用'SlowCheetah'VS扩展来根据项目配置使用不同的值转换app.config . 因此,'Debug'配置会生成一个app.config,其值适合Dev / Qa用户,而'Release'版本会生成一个带有 生产环境 值的app.config .

.csproj包含这样的部分:

<ItemGroup>
<None Include="App.config">
  <SubType>Designer</SubType>
  <TransformOnBuild>true</TransformOnBuild>
</None>
<None Include="App.Debug.config">
  <DependentUpon>App.config</DependentUpon>
  <IsTransformFile>True</IsTransformFile>
  <SubType>Designer</SubType>
</None>    
<None Include="App.Release.config">
  <DependentUpon>App.config</DependentUpon>
  <IsTransformFile >True</IsTransformFile>    
</None>
<None Include="packages.config" />
<None Include="Properties\SlowCheetah\SlowCheetah.Transforms.targets" />

msbuild逻辑主要包含在'SlowCheetah.Transforms.targets'文件中 . 我的文件正在正确转换 .

我想防止开发人员在Visual Studio中意外运行“Release”构建并无意中使用 生产环境 配置文件运行我的应用程序 . 我的想法是使用msbuild条件,可能是这样的:

Condition=" '$(BuildingInsideVisualStudio)'=='true' "

我已经尝试在.csproj文件中的几个地方使用此条件但没有成功 . 我怀疑如果我修改'SlowCheetah.Transforms.targets'文件本身,我可以让它工作,但不应该根据顶部的注释修改该文件 .

理想情况下,我希望Visual Studio中的所有构建配置都使用我的Debug配置文件,并在Visual Studio外部构建“Release”(例如在持续集成服务器上构建)以使用Prod app.config,但我会满足于能够防止意外运行Visual Studio中的“Release”构建 . 关于是否/如何实现这一点的任何建议都表示赞赏 .

1 回答

  • 1

    </Project> 之前添加:

    <Target Name="BeforeBuild">
        <Error Condition=" '$(BuildingInsideVisualStudio)'=='true' And '$(Configuration)'=='Release' "
               Text="JMc is so mad at you you trying to build using the Release configuration from Visual Studio." />
      </Target>
    

相关问题