在MSBuild中可以确定我是否正在Visual Studio中运行 [英] In MSBuild is it possible to determine if I'm running in Visual Studio

查看:91
本文介绍了在MSBuild中可以确定我是否正在Visual Studio中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio是否设置了任何MSBuild属性?我希望根据Visual Studio的版本(如果有)有一些条件性行为.

Are the any MSBuild properties that Visual Studio sets? I'm looking to have some conditional behavior depending on the version (if any) of visual studio.

推荐答案

您应使用的属性值为BuildingInsideVisualStudio,当您在Visual Studio中构建该属性时,该属性将设置为true.由于ProductVersion是在项目文件中声明的,因此您无法使用它,因为无论是在VS内部还是通过msbuild.exe构建,它都具有相同的值.

The property value you should be using is BuildingInsideVisualStudio, when you are building inside of Visual Studio this property will be set to true. Since ProductVersion is declared in the project file you cannot use it because it will have the same value whether building inside of VS or via msbuild.exe.

<PropertyGroup>
    <MyProp Condition=" '$(BuildingInsideVisualStudio)' == 'true' ">Foo</MyProp>  
    <MyProp Condition=" '$(BuildingInsideVisualStudio)' != 'true' ">Bar</MyProp> 
</PropertyGroup>

这篇关于在MSBuild中可以确定我是否正在Visual Studio中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆