I'm using default Roslyn SDK templates that came with Visual Studio 2017. The projects they create target .NET Framework Portable. I'm assuming Roslyn extensibility projects can target .NET Standard \ Core instead of Portable and I'm looking for templates or a sample of Roslyn Analyzer \ Refactoring project that I could study.
I started working on a new Roslyn project and built things one by one instead of using template. https://github.com/IKoshelev/Roslyn.AutoLogging/commit/1f88e3e49141e0fa425c51fdcb3457a7c3d6dcaa
I managed to have the following targeting:
Refactoring project - .NET Standard 1.3 (this .dll will be distributed, version kept to minimum)
UnitTests project - .NET Core 2.0
VSIX project - .NET Framework 4.6 (I believe, only full Visual Studio supports VSIX, so that is okay)
Update Versioning of Roslyn is a bit more complicated right now, i.e. if you want to use your extensions with Visual Studio 2015 you will have to use PCL libraries. More info at the end of this article article on Roslyn
Sample of converted analyzer from default analyzer template is available here. There is original analyzer for comparison along with TestAnalyzerStandard
which targets .NET standard.
Steps to make it work:
- Create new .NET Standard library
- Library must target .NET Standard 1.3. This is required if you wish to run analyzer as extension inside VS (extensions target .NET 4.6). Mapping between standard versions and full framework versions is available here. Also if you try to target lower version than 1.3, you will not be able to include required analyzer packages.
- Add nuget package for
Microsoft.Composition
latest version. This is needed byMicrosoft.CodeAnalysis.CSharp.Workspaces
. If you try to add workspaces first, you will get error that referenced composition package is not compatible. - Add nuget package for
Microsoft.CodeAnalysis.CSharp
(I'm using latest 1.* version) - Add nuget package for
Microsoft.CodeAnalysis.Csharp.Workspaces
(version should match the version ofMicrosoft.CodeAnalysis.CSharp
). - At this point you can copy code from portable project and build it. There should be no errors (you may have to close and reopen solution if VS is still displaying red squiggles).
- To make VS extension work, just open
source.extension.vsixmanifest
, go to assets tab and change reference to .NET standard library - To create .nuget package just execute
nuget pack Diagnostic.nuspec .
.Diagnostic.nuspec
is valid for Nuget 2.x. If you are using nuget via package management console in VS 2017 you will have to change<file src="*.dll" ..."
to<file src="bin\*\netstandard1.3\*.dll" ...
.
Those steps are result of my experimentation with analyzers (I previously played with creating DLL which targeted full framework instead of being portable library). They are not by any means official.
.csproj
file to point to Diagnostic.nuspec
for packaging. You can now build nuget package directly from Visual Studio by right clicking TestAnalyzerStandard
-> Pack
. Nuget package will be present in Debug (or Release) folder. I also included built vsix extension and nuget package in TestAnalyzerStandard\Publish
folder so you can see what is produced on my machine. –
Paymaster I started working on a new Roslyn project and built things one by one instead of using template. https://github.com/IKoshelev/Roslyn.AutoLogging/commit/1f88e3e49141e0fa425c51fdcb3457a7c3d6dcaa
I managed to have the following targeting:
Refactoring project - .NET Standard 1.3 (this .dll will be distributed, version kept to minimum)
UnitTests project - .NET Core 2.0
VSIX project - .NET Framework 4.6 (I believe, only full Visual Studio supports VSIX, so that is okay)
Update Versioning of Roslyn is a bit more complicated right now, i.e. if you want to use your extensions with Visual Studio 2015 you will have to use PCL libraries. More info at the end of this article article on Roslyn
© 2022 - 2024 — McMap. All rights reserved.