Skip to content

Instantly share code, notes, and snippets.

@VahidN
Last active August 13, 2019 07:10
Show Gist options
  • Save VahidN/95653b52784026f44a6f8b1bf9733e60 to your computer and use it in GitHub Desktop.
Save VahidN/95653b52784026f44a6f8b1bf9733e60 to your computer and use it in GitHub Desktop.
How to activate Roslynator for Visual Studio Code
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=`"jiContent`" 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]
Write-Host $jsonText
$json = ConvertFrom-Json $jsonText
$version = $Json.MoreInfo.VersionValue # 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 "Delete old .dll files."
Remove-Item "$currentDir\*.dll"
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*"
$omnisharpJsonFilePath = "$env:USERPROFILE\.omnisharp\omnisharp.json";
Write-Host "Create $omnisharpJsonFilePath file."
$omnisharpJson = @"
{{
"RoslynExtensionsOptions": {{
"enableAnalyzersSupport": true,
"LocationPaths": [
"{0}"
]
}}
}}
"@ -f $currentDir -Replace "\\","\\"
$omnisharpJson | Out-File "$omnisharpJsonFilePath" -Confirm
Write-Host "Done!"
}
else
{
Write-Host "Failed to find the packageUrl!"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment