Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use an altered Roslyn in Visual Studio

C# isn't enough for me, so I've taken advantage of the newly-open sourced Roslyn to extend it, say by modifying it to use French quotes.

But I don't want to build my newly-French-quoted files on the command line! I want Intellisense! I want a nice UI! In short, I want to get Visual Studio to use my Roslyn, not Microsoft's.

Can I do this yet? If so, how?

like image 532
Rawling Avatar asked Apr 04 '14 08:04

Rawling


People also ask

Does Visual Studio use Roslyn?

Visual Studio includes a core set of . NET Compiler Platform (Roslyn) analyzers. These analyzers are always on.

What are analyzers in Visual Studio?

NET Compiler Platform (Roslyn) Analyzers inspect your C# or Visual Basic code for style, quality, maintainability, design, and other issues. This inspection or analysis happens during design time in all open files. Analyzers are divided into the following groups: Code style analyzers are built into Visual Studio.


1 Answers

Quoted straight from this link in your question:

ADVANCED USAGE

It is also possible to update your copy of Visual Studio to use your own built version of Roslyn (for example, to see how the IDE reacts to your changes), but it’s slightly complicated:

First of all, you’ll need to use the release fork, not the master fork. This is because the compiler code is constantly changing in reaction to feedback, and that includes changes to the APIs that are used by the non-open IDE bits in the Roslyn preview in order to access compiler information (until the APIs get locked down as we get closer to completion). When these APIs change, the ability to communicate between the two is lost. The release fork, however, accurately reflects the state of the code at the time that the Roslyn preview was snapped, and so is safe to use as a baseline for this sort of thing. (You can see the fork on the Roslyn CodePlex site by choosing “Source Code” and then opening the “Browsing changes in” dropdown – it’s called “releases\build-preview.”)

To switch to this fork in Git, you will need to execute the following two commands from an appropriate Git prompt in your enlistment:

Git fetch

Git checkout – track origin/releases/build-preview

Your git repository will now have the contents of the releases/build-preview branch. Once you’ve done this, you can switch back and forth between the branches using Git checkout master and git checkout releases/build-preview. (Details on Git usage are beyond the scope of this blog; see http://www.git-scm.com/book/en/Git-Branching-Remote-Branches for more information on branching in Git.)

Second, you’ll need to disable Visual Studio’s strong-name assembly checking for the relevant assemblies first. There’s a script to help with that, which you can find checked into the source code at Src/Tools/Microsoft.CodeAnalysis.Toolset.Open/Scripts/Prepare.bat.

With all of that done, make your changes. Then, after building, ensure that CompilerPackage is set as the startup project, and then F5/Ctrl+F5 to launch a VS instance containing the changes.

Please note that we will never accept pull requests for the release fork – we need to keep it pristine and accurately reflecting the state of the code relative to the Roslyn preview bits. Anything you actually want considered for submission would need to be ported to a fork created from the master first.

Interesting times ahead. Though I have a certain amount of trepidation about finding myself in a company where they use an entirely customised compiler to do awful, awful things. The gun to shoot yourself in the foot with has just been upgraded...

like image 164
Adam Houldsworth Avatar answered Oct 21 '22 08:10

Adam Houldsworth