MSBuild条件,以防止app.config XML转换
问题描述:
我正在使用'SlowCheetah'VS扩展根据项目配置使用不同的值转换我们的app.config。因此,'Debug'配置会生成一个具有适合Dev/Qa用户的值的app.config,而'Release'构建会生成带有生产值的app.config。MSBuild条件,以防止app.config XML转换
的.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中运行“发布”版本,并在无意中使用生产配置文件运行我的应用程序。我的想法是使用一个MSBuild情况,可能是这样的:
Condition=" '$(BuildingInsideVisualStudio)'=='true' "
我在没有成功的.csproj文件的几个地方使用这个条件尝试。如果我修改'SlowCheetah.Transforms.targets'文件本身,我怀疑我可以让它工作,但不应该根据顶部的注释修改该文件。
理想情况下,我希望Visual Studio中的所有配置可以使用我的调试配置文件,而'发布'构建Visual Studio外部(例如构建在持续集成服务器上)以使用Prod app.config,但是我对于能够防止Visual Studio中'发布'版本的意外运行,我感到很满意。任何有关如何/如何实现这一目标的建议都会受到赞赏。
答
只是</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>
很好地做这项工作。谢谢。 – JMc
使用相同条件的一个好的替代方法是在app.config中指定DEV值并为“发布”配置指定一个单独的变换。然后将“条件”放置在“SlowCheetah”属性组中。结果是,转换只发生在VS外部时。当在VS内部构建时,您总是以DEV app.config文件结束。 – JMc