1

我正在使用“SlowCheetah”VS 扩展来根据项目配置使用不同的值转换我们的 app.config。因此,“调试”配置会生成具有适合 Dev/Qa 用户的值的 app.config,而“发布”构建会生成具有生产值的 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 中运行“发布”版本并无意中使用生产配置文件运行我的应用程序。我的想法是使用 msbuild 条件,可能类似于:

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

我尝试在 .csproj 文件中的多个位置使用此条件,但均未成功。我怀疑如果我修改“SlowCheetah.Transforms.targets”文件本身,我可以让它工作,但不应该根据顶部的评论修改该文件。

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

4

1 回答 1

2

在之前添加</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>
于 2017-01-24T21:28:55.553 回答