我正在使用'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,但是我d能够防止意外运行Visual Studio中的“Release”构建。关于是否/如何实现这一点的任何建议都表示赞赏。
答案 0 :(得分: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>