In MSBuild is it possible to determine if I'm running in Visual Studio

后端 未结 4 1283
情话喂你
情话喂你 2021-02-05 01:36

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.

相关标签:
4条回答
  • 2021-02-05 02:26

    To directly address the question in your title - if you just want to know if you are being built from VS or not, check the value of IsDesktopBuild which will return true or false appropriately.

    0 讨论(0)
  • 2021-02-05 02:29

    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>
    
    0 讨论(0)
  • 2021-02-05 02:32

    <ProductVersion> will give you the version of MSBuild that is running the build process.

    Note that in VS 2010 the build process might be targeting either .Net 4.0 or 3.5 You need to consider carefully if your conditional compilation depends on the msbuild version itself or on the target framework of the build and the tools the build is using. If your condition is based on the target framework, use <TargetFrameworkVersion>.

    Of course, if your build also might be run under VS 2008, you need to support proper fallback if <TargetFrameworkVersion> is missing.

    0 讨论(0)
  • 2021-02-05 02:38

    Yes, <ProductVersion> is listed in a project file. It matches the Visual Studio version number.

    0 讨论(0)
提交回复
热议问题