Visual studio project, how to check if project is VB or C#

575 Views Asked by At

I'd like to create a targets file that is compatible with C# and VB projects, unfortunately it needs knowledge of the project language.

I could just make one file for each language, but it would be cleaner if I could just use one file, and have a condition that checks which language we need.

Is there a way of doing this?

I was hoping for something like this:

<Target Name="BeforeBuild" Condition="'$(Language)"' == 'C#'">

or

<Target Name="BeforeBuild" Condition="'$(ProjectFile).Extension' == 'csproj'">

I've tried searching, but there is a lot of noise for these search terms. I've tried many variations on the following terms with no luck.

  • msbuild project check language
  • msbuild project condition if vb or c#
  • csproj check language

If we get a good answer, hopefully the next person will find this a lot easier to find an answer for.

1

There are 1 best solutions below

0
Rubidium 37 On

Recently, I successfully used "MSBuildProjectExtension" inside Directory.Build.props, as in the following example:

<PropertyGroup Condition="'$(MSBuildProjectExtension)'=='.csproj'">
    <LangVersion>preview</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(MSBuildProjectExtension)'=='.vbproj'">
    <LangVersion>latest</LangVersion>
</PropertyGroup>