Version Used:
Microsoft Visual Studio Enterprise 2017
VisualStudio/15.0.0+26228.10
Steps to Reproduce:
Expected Behavior:
Actual Behavior:
An error message:
Could not install package 'Microsoft.CodeAnalysis.Common 2.0.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile7', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
It seems like this is because Microsoft.CodeAnalysis.Common is now only built for .NET Standard 1.3. If I manually reference this assembly from my existing analyzer, I get a Code Analysis error:
MSBUILD : error : CA0001 : Could not find type 'System.Runtime.CompilerServices.ConditionalWeakTable`2' in assembly 'Microsoft.CodeAnalysis, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'.
+1
I am trying to do the same thing and I am getting the same error as well.
Could not install package 'Microsoft.CodeAnalysis.Common 2.0.0'. You are trying to install this package into a project that targets '.NETPortable,Version=v4.5,Profile=Profile7', but the package does not contain any assembly references or content files that are compatible with that framework.
I am using Visual Studios 2015 Community Edition for creating new Analyzer project from the "Analyzer with Code Fix (NuGet + VSIX)" template
Related to https://github.com/dotnet/roslyn/issues/15978#issuecomment-280864275.
Portable projects cannot reference Netstandard 1.3 libraries. I'll need to create a new set of project templates that target Netstandard 1.3. As an aside, 2.0 has no new apis @yaakov-h what was your reasoning for upgrading?
@jmarolf, we were under the impression that support for the new C#7 syntax was provided through the Roslyn 2.0 libraries. was this incorrect?
Yes @brian-reichle is correct. I tried to write an analyzer/fixer that uses the Tuple syntax factory methods, and these are only available in 2.0.0 libraries.
@jmarolf Can you post a workaround on #15978 until we have published the new templates?
@mavasani @jmarolf does this imply that both the workaround and the solution are that Analyzers for 2.0/C#7/etc. must now be .NET Standard 1.3 libraries instead of PCL libraries?
@brian-reichle I was hoping the answer @yaakov-h had was that he wanted to write an analyzer against the new C#7 syntax, but if that was not the case then they could have continued without upgrading.
@mavasani I am not aware of anyway for Portable7 projects to reference netstandard 1.3 nuget packages.
does this imply that both the workaround and the solution are that Analyzers for 2.0/C#7/etc. must now be .NET Standard 1.3 libraries instead of PCL libraries?
@yaakov-h yes netdstandard has a much larger surface area than PCLs in terms of APIs. You cannot reference a netstandard library from a PCL (though the reverse is possible).
@jmarolf the answer @brian-reichle gave is mine as well, we're working on the same Analyzers. 馃槃
@yaakov-h @brian-reichle Ah, well I am sorry that I have no easy fix for you other than creating a new netstandard project. I don't think I'll have time this week to publish those new templates :( but here is an example project file on a netstandard project that should get you started.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard1.3</TargetFramework>
<PackageTargetFallback>portable-net45+win8+wp8+wpa81</PackageTargetFallback>
<IncludeBuildOutput>false</IncludeBuildOutput>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup>
<PackageId>Analyzer3</PackageId>
<PackageVersion>1.0.0.0</PackageVersion>
<Authors>jmarolf</Authors>
<PackageLicenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</PackageLicenseUrl>
<PackageProjectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</PackageProjectUrl>
<PackageIconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</PackageIconUrl>
<RepositoryUrl>http://REPOSITORY_URL_HERE_OR_DELETE_THIS_LINE</RepositoryUrl>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Description>Analyzer3</Description>
<PackageReleaseNotes>Summary of changes made in this release of the package.</PackageReleaseNotes>
<Copyright>Copyright</Copyright>
<PackageTags>Analyzer3, analyzers</PackageTags>
<NoPackageAnalysis>true</NoPackageAnalysis>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.0.0" PrivateAssets="all" />
<PackageReference Update="NETStandard.Library" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<Compile Update="Resources.Designer.cs" DesignTime="True" AutoGen="True" DependentUpon="Resources.resx" />
<EmbeddedResource Update="Resources.resx" Generator="ResXFileCodeGenerator" LastGenOutput="Resources.Designer.cs" />
</ItemGroup>
<ItemGroup>
<None Update="tools\*.ps1" CopyToOutputDirectory="Always" Pack="true" PackagePath="tools" />
<None Include="$(OutputPath)\$(AssemblyName).dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
</ItemGroup>
</Project>
It doesn't seem like I can manually install the Microsoft.CodeAnalysis.CSharp.Workspaces package into a .NET Standard 1.3 project...
Restoring packages for C:\Blah\Analyzers.csproj...
Restoring packages for C:\Blah\Analyzers.csproj...
Package Microsoft.Composition 1.0.27 is not compatible with netstandard1.3 (.NETStandard,Version=v1.3). Package Microsoft.Composition 1.0.27 supports: portable-net45+win8+wp8+wpa81 (.NETPortable,Version=v0.0,Profile=Profile259)
One or more packages are incompatible with .NETStandard,Version=v1.3.
Package restore failed. Rolling back package changes for 'Analyzers'.
Time Elapsed: 00:00:01.0730152
========== Finished ==========
I tried to manually add the PackageReference element to the csproj and now I'm getting compiler errors relating to System.Composition not existing.
I'd guess it might be possible to build a 2.0-targeting Analyzer if I reference .NET 4.6, but it appears to be impossible with .NET Standard.
@yaakov-h you need <PackageTargetFallback>portable-net45+win8+wp8+wpa81</PackageTargetFallback> in your csproj file
@jmarolf aha, I missed that detail. Thanks!
I tried the suggestions, but with the netstandard project format I'm having trouble using an external dependency (JSON.NET). Since PackageReferences are not copied to the bin directory, I cannot include them in the nuget-package. If they are not included in the nuget analyzers folder, VS will complain of course.
Is there a way to force the referenced dll to be placed into the output directory so that they can be included?
@aKzenT I'm pretty sure you can do that with Copy Local, even with the new SDK.
Correct me if I'm wrong, but I don't think there is a "Copy Local" option when using PackageReference. I don't see any option for it in the VS IDE and I also don't see any option documented in https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files
I think you're right. I take that back then.
I had a problem with the sample project file. In my case the nuget file was created before the dll's were created in the output folder. I head to build twice to get my nuget package without missing entry's. I then used IsTool, but then those files are not where they should be :/
It has been a few months, @jmarolf, is there a issue tracking the progress of updating the templates that come in the .NET Compiler Platform SDK that I can follow? I just downloaded the SDK and the template in Visual Studio 2017 Update 2 still generates a 1.0.1 Roslyn project using a PCL library.
Here is a similar issue about the templates, linking it to join them together https://github.com/dotnet/roslyn/issues/18954
@jmarolf
<None Update="tools\*.ps1" CopyToOutputDirectory="Always" Pack="true" PackagePath="tools" />
should be:
<None Update="tools\*.ps1" CopyToOutputDirectory="Always" Pack="true" PackagePath="" />
to prevent creating tools\tools\install.ps1 inside the nupkg. See https://github.com/NuGet/Home/wiki/Adding-nuget-pack-as-a-msbuild-target for details.
Issue moved to dotnet/roslyn-sdk #73 via ZenHub