dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.68k stars 1.06k forks source link

Import language targets conditional on proj file extension #1051

Open srivatsn opened 7 years ago

srivatsn commented 7 years ago

From @dazinator on March 26, 2017 16:25

This is in the SDK targets:

  </Import>

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.targets
============================================================================================================================================
-->
  <PropertyGroup Condition="'$(LanguageTargets)' == ''" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <LanguageTargets Condition="'$(MSBuildProjectExtension)' == '.csproj'">$(MSBuildToolsPath)\Microsoft.CSharp.targets</LanguageTargets>
    <LanguageTargets Condition="'$(MSBuildProjectExtension)' == '.vbproj'">$(MSBuildToolsPath)\Microsoft.VisualBasic.targets</LanguageTargets>
    <!-- If LanguageTargets isn't otherwise set, then just import the common targets.  This should allow the restore target to run,
         which could bring in NuGet packages that set the LanguageTargets to something else.  This means support for different
         languages could either be supplied via an SDK or via a NuGet package. -->
    <LanguageTargets Condition="'$(LanguageTargets)' == ''">$(MSBuildToolsPath)\Microsoft.Common.CurrentVersion.targets</LanguageTargets>
  </PropertyGroup>

Shouldn't the language targets be imported based on a capability( i.e CSharp), not project file extension?

I currently have to manually import the csharp targets into my custom project (.dnnproj), when using the new proj file format.. event though I declare CSharp capability.

Copied from original issue: Microsoft/VSProjectSystem#219

srivatsn commented 7 years ago

From @dazinator on March 26, 2017 22:54

Ok so this also seems to be the reason why Roslyn compilation can't find assemblies referenced via PackageReference - which I raised in #218

Declaring the following LanguageTargets property, in my custom project system props file, seems to fix everything, and I no need to directly import the csharp targets anymore in my project system

  <PropertyGroup>
 <LanguageTargets>$(MSBuildToolsPath)\Microsoft.CSharp.targets</LanguageTargets>  
  </PropertyGroup>
borgdylan commented 7 years ago

The capability gets added based on the extension as well, so this will not work.

dazinator commented 7 years ago

Yes it will work.. The capability is inferred based on extension (Csproj / Vbproj etc) which works fine for those projects. For custom project types though, i.e with a different extension (e.g dnnproj) they declare their own capabilities.. They would include any relevent language capabilities in their own targets - i.e csharp.

dazinator commented 7 years ago

Honestly dont see the point of a csharp language capability if it cant be used to infer the language.

github-actions[bot] commented 5 months ago

Due to lack of recent activity, this issue has been labeled as 'stale'. It will be closed if no further activity occurs within 30 more days. Any new comment will remove the label.

dazinator commented 5 months ago

I no longer develop custom project types. However I think this should be active until someone can confirm if anything has already been or will be done:

Honestly dont see the point of a csharp language capability if it cant be used to infer the language.