Comments (37)
Roslynator for Visual Studio Code is here! https://marketplace.visualstudio.com/items?itemName=josefpihrt-vscode.roslynator
from roslynator.
A PowerShell script to automate this process
Write-Host "Download, unzip and enable Roslynator for Visual Studio Code"
$name = "josefpihrt.Roslynator2017"
$url = "https://marketplace.visualstudio.com/items?itemName=$name"
$currentDir = $PSScriptRoot
$file = "$currentDir\Roslynator.zip"
$pattern = "<script class=`"vss-extension`" defer=`"defer`" type=`"application\/json`">(.*?)<\/script>"
$regex = [regex]"(?m)$pattern"
Write-Host "Grab the home page of the $name."
$dom = (New-Object Net.WebClient).DownloadString($url);
if($dom -and $dom -match $pattern)
{
$matches = $regex.Match($dom)
$jsonText = $matches[0].Groups[1]
$json = ConvertFrom-Json $jsonText
$version = $Json.versions[0].version # Parse the json in the page for the latest version number
$parts = $name.Split(".")
$publisher = $parts[0]
$package = $parts[1]
# Assemble the url for the vsix package
$packageUrl = "https://marketplace.visualstudio.com/_apis/public/gallery/publishers/$publisher/vsextensions/$package/$version/vspackage"
Write-Host "Download the vsix package: $packageUrl"
(New-Object Net.WebClient).DownloadFile($packageUrl, $file)
Write-Host "Using $currentDir as the current dir."
Write-Host "Unzip $file."
$shellApp = new-object -com shell.application
$zipFile = $shellApp.namespace($file)
$destination = $shellApp.namespace($currentDir)
$destination.Copyhere($zipFile.items(), 0x14) # overwrite and be silent
Write-Host "Delete VS specific files. Otherwise they will interfere with the MEF services inside OmniSharp."
Remove-Item "$currentDir\Roslynator.VisualStudio.Core.dll","$currentDir\Roslynator.VisualStudio.dll", "$currentDir\Roslynator.VisualStudio.pkgdef"
$omnisharpJsonFilePath = "$env:USERPROFILE\.omnisharp\omnisharp.json";
Write-Host "Create $omnisharpJsonFilePath file."
$omnisharpJson = @"
{{
"RoslynExtensionsOptions": {{
"LocationPaths": [
"{0}"
]
}}
}}
"@ -f $currentDir -Replace "\\","\\"
$omnisharpJson | Out-File "$omnisharpJsonFilePath" -Confirm
Write-Host "Done!"
}
else
{
Write-Host "Failed to find the packageUrl!"
}
from roslynator.
Roslyn analyzers and code fixes support was merged recently into omnisharp-roslyn so this should now be possible.
Until a new preference and an updated stable release of omnisharp-roslyn gets shipped, you'll need to use "omnisharp.path": "latest"
in your settings.json and the following in your omnisharp.json:
{
"RoslynExtensionsOptions": {
"EnableAnalyzersSupport": true,
"LocationPaths": [
"C:\\lib\\roslynator"
]
}
}
I've tested this recently and was able to get both analyzer warnings/errors as well as codefixes.
from roslynator.
I think this should work:
string localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string path = @"%LOCALAPPDATA%/JosefPihrt/Roslynator/VisualStudioCode";
path = path.Replace("%LOCALAPPDATA%", localAppDataPath);
// "/home/foo/.local/share/JosefPihrt/Roslynator/VisualStudioCode" on Linux with user "foo"
Console.WriteLine(path);
On Windows there will be mixed slashes but I have checked that it's fine.
from roslynator.
I'll give it a try then, and report the results :)
from roslynator.
Can we remove the blocked label at this point?
from roslynator.
I would like to, but currently it is not possible.
from roslynator.
https://www.strathweb.com/2017/05/using-roslyn-refactorings-with-omnisharp-and-visual-studio-code/
from roslynator.
So is this still blocked? Or is it now possible to make a VSCode Roslynator Add-in?
from roslynator.
I don't think it is possible yet, you can check that the issue mentioned above is still open.
from roslynator.
How to enable Roslynator for VS Code
from roslynator.
@josefpihrt I've tried following those instructions, but get:
System.NotSupportedException: An attempt was made to load an assembly from a network location which would have caused the assembly to be sandboxed in previous versions of the .NET Framework. This release of the .NET Framework does not enable CAS policy by default [...]
I fixed that by "unblocking" the assemblies in Windows (7). Now I'm getting:
Expected to use Roslynator.CSharp.CodeFixes, Version=1.6.30.0, Culture=neutral, PublicKeyToken=94dac60bcac1903d in host services but the assembly cannot be loaded due to an exception: Could not load file or assembly 'Roslynator.Workspaces, Version=1.6.30.0, Culture=neutral, PublicKeyToken=8ca34578834dd224' or one of its dependencies. The system cannot find the file specified.. System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
Any suggestions?
from roslynator.
Copying Roslynator.Workspaces.dll to your folder should solve the issue.
I have recently move code dependent on Microsoft.CodeAnalysis.CSharp.Workspaces to new assembly Roslynator.Workspaces but I have not update documentation yet.
from roslynator.
Thanks! One other thing to note is that I needed to restart VS Code to get it to load the DLLs. Simply restarting the Omnisharp extension was not sufficient. Maybe that's only the case when there are problems reading assemblies, and it's not a general problem if you manage to get your configuration right on your first try.
- Extract DLLs
- Unblock DLLs in Windows
- Add/create settings in omnisharp.json
- Start (or restart) VS Code
from roslynator.
I'm glad it works!
I will update documentation accordingly.
from roslynator.
Are these DLLs .NET Standard? I mean, would that work with VS Code on Mac?
from roslynator.
Roslynator targets .NET Standard 1.3
from roslynator.
Looks like the new preference is available in the latest omnisharp. This will remove the need for the "EnableAnalyzersSupport" setting in your omnisharp.json.
from roslynator.
Does anybody know how to pack roslyn libraries as VS Code extension?
from roslynator.
This is fantastic news!
One thing. Currently user-level rules can be set by creating files at %LOCALAPPDATA%\JosefPihrt\Roslynator. This isn't possible for people running VS Code on non-Windows environments.
I think you could just update roslyn/common/roslynator.config within the extension to include a couple of extra imports like:
<Include Path="~/roslynator.config" />
...
<RuleSet Path="~/roslynator.ruleset" />
and users would be able to create a config and ruleset in their home directory?
from roslynator.
I should not be necessary to add more paths to roslynator config. It should be sufficient to replace %LOCALAPPDATA%
with value of returned by Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
.
I do not have OSX or Linux installed on my machine but I found this page that lists all values:
ENM: System.Environment.SpecialFolder.LocalApplicationData
WIN: C:\Users\foo\AppData\Local
LIN: /home/foo/.local/share
OSX: /Users/foo/.local/share
from roslynator.
Is anybody able to test that following code snippet will work on non-Windows environment?
using System;
using System.IO;
using System.Diagnostics;
string localAppDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
string path = @"%LOCALAPPDATA%\JosefPihrt\Roslynator\VisualStudioCode";
path = path.Replace("%LOCALAPPDATA%", localAppDataPath);
// normalize directory separator
path = Path.GetFullPath(path);
// LINUX
Debug.Assert(path == "/home/foo/.local/share/JosefPihrt/Roslynator/VisualStudioCode");
// OSX
Debug.Assert(path == "/Users/foo/.local/share/JosefPihrt/Roslynator/VisualStudioCode");
Thanks.
from roslynator.
When I replaced /home/foo/
with my current user directory on Linux Assert failed because of wrong slashes.
Otherwise path looks fine (I added Console.WriteLine) :)
My Linux is some kind of Debian (9 I think) and my dotnet version is 2.2.300
from roslynator.
@josefpihrt yes, your way is definitely better than adding more paths.
As domints says, the directory normalizing isn't working.
You could do something like
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
{
path = path.Replace(@"\", "/");
}
Or else I think just using forward slashes as directory separators will work across all platforms?
from roslynator.
You could use Path.PathSeparator for platform aware separators
from roslynator.
@sbmw that's not the good way :) I believe System.IO.Path has field specifying the correct path delimiter. It's DirectorySeparatorChar
. But as AltDirectorySeparatorChar
specifies on Windows, Windows also understands /
slash, so that might be a way to go.
I think GetFullPath
didn't fix slashes on Linux, because neither DirectorySeparatorChar
nor AltDirectorySeparatorChar
specify \
as proper separator on Linux.
@divinebovine Path.PathSeparator
is meant to separate multiple paths, not directories in single path. It resolves to ;
on Windows and :
on Linux.
from roslynator.
There is Path.Combine to combine path parts.
from roslynator.
@domints you're right, my mistake
from roslynator.
There is Path.Combine to combine path parts.
yet it doesn't fix anything :)
from roslynator.
Realy, I haven't read back enough posts...
Joining to @domints: doesn't / work on windows? Or you can expect / and replace it with Path.DirectorySeparatorChar.
According to this / should work on windows too:
https://docs.microsoft.com/en-us/dotnet/api/system.io.path.directoryseparatorchar?view=netframework-4.8
from roslynator.
how can i get roslynator to work with macos
from roslynator.
how can i get roslynator to work with macos
Just install VS Code extension and modify one file according to readme on extension page
from roslynator.
from roslynator.
from roslynator.
Ok the assemblies seem to load but still doesnt work :(
Can someone else confirm that works for mac
from roslynator.
from roslynator.
I'm going to close this issue. Please file a new issue for anything related to VS Code. Thanks.
from roslynator.
Related Issues (20)
- RCS1261: "Resource can be disposed asynchronously" does not take lock statement into account
- About new packages HOT 4
- Consider disabling `RCS1223` for attributes HOT 2
- RCS1159 should not be reported for WPF routed events HOT 2
- Declare as nullable code fix for CS8600 breaks when casts are involved HOT 1
- Simplify numeric comparison HOT 7
- Consider disabling `RCS0012` for fields HOT 1
- `RCS1019` does not work for `file static` HOT 1
- Collection expressions are not considered "obvious" typing
- `RCS1250` fixer cannot handle collection expressions
- `RCS1250` Applies collection-expression fixer when properties are set.
- RCS1060 doesn't work with file-scoped namespaces HOT 2
- CS8032: An instance of analyzer Roslynator.CSharp.Analysis.UnnecessaryRawStringLiteralAnalyzer cannot be created HOT 2
- RCS1267 - propose wrong fix
- Some analyzers don't work in Rider with severity being set to "suggestion" HOT 1
- RCS1169 not being diffused by roslynator_unity_code_analysis.enabled = true HOT 4
- RCS1077 Crashes with NullReference Exception HOT 2
- Typo in new option key
- Missing documentation HOT 7
- Add performance refactoring for IList Last, First or ElementAt HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from roslynator.