New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unable to create an Analyzer targeting Roslyn 2.0 #18414
Comments
+1 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 #15978 (comment). |
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. |
@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. |
@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...
|
I tried to manually add the 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 |
@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 #18954 |
should be:
to prevent creating |
Issue moved to dotnet/roslyn-sdk #73 via ZenHub |
Version Used:
Microsoft Visual Studio Enterprise 2017
VisualStudio/15.0.0+26228.10
Steps to Reproduce:
Expected Behavior:
Actual Behavior:
An error message:
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:
The text was updated successfully, but these errors were encountered: