Вопрос

I have some C# code that only works in Visual Studio 2012 but I also use Visual Studio 2010 on the same codebase. Is there a preprocessor directive or a conditional I can use to isolate the code?

Это было полезно?

Решение

No built in pre-processor directive as far as I know, but there is an MSBuild variable.

Open the project file (unload it in Solution Explorer, then click edit) and add the following after the main set of property declarations.

<PropertyGroup Condition="'$(VisualStudioVersion)' == '10.0'">
  <DefineConstants>$(DefineConstants);VS_10;</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition="'$(VisualStudioVersion)' == '11.0'">
  <DefineConstants>$(DefineConstants);VS_11;</DefineConstants>
</PropertyGroup>

You can then use the VS_10 (VS 2010) or VS_11 (VS 2012) preproc directives.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top