docs/contributing/Building, Debugging, and Testing on Windows.md
Using the command line, Roslyn can be developed using the following pattern:
The minimal required version of .NET Framework is 4.7.2.
sdk.version property in global.jsonSee the Building, Debugging, and Testing on Unix documentation to get started developing Roslyn using Visual Studio Code.
There are a number of options for running the core Roslyn unit tests:
The Test.cmd script will run our unit test on already built binaries. It can be passed the -build argument to force a new build before running tests.
Test.cmd in the command prompt.You can more precisely control how the tests are run by running the eng/build.ps1 script directly with the relevant options. For example passing in the -test switch will run the tests on .NET Framework, whilst passing in the -testCoreClr switch will run the tests on .NET Core.
The results of the tests can be viewed in the artifacts/TestResults directory.
Tests can be run and debugged from the Test Explorer window. For best performance, we recommend the following:
__NonExistent__ to hide all tests from the UITests can be run and debugged under WSL. This requires a bit of setup the first time. After that, it is as easy as selecting WSL as the active environment in Test Explorer.
wsl --install (details)To debug through tests, you can right click the test project that contains your tests and choose Set as Startup Project. Then press F5. This will run the tests under the command line runner. Some members of the team have been working on a GUI runner that allows selection of individual tests, etc. Grab the source from xunit.runner.wpf, build it and give it a try.
You can build and deploy with the following command:
.\Build.cmd -Restore -Configuration Release -deployExtensions -launch.
Then you can launch the RoslynDev hive with devenv /rootSuffix RoslynDev.
The Rosyln solution is designed to support easy debugging via F5. Several of our projects produce VSIX which deploy into Visual Studio during build. The F5 operation will start a new Visual Studio instance using those VSIX which override our installed binaries. This means trying out a change to the language, IDE or debugger is as simple as hitting F5. Note that for changes to the compiler, out-of-process builds won't use the privately built version of the compiler.
The startup project needs to be set to RoslynDeployment. This should be the default but in some cases will need to be set explicitly. To set it, right-click the RoslynDeployment project in Solution Explorer and select "Set as Startup Project".
RoslynDeployment is a container project located in the src/Deployment folder that
bundles and deploys all the main Roslyn extensions together. When you press F5 with
RoslynDeployment set as the startup project, it will deploy all of the following extensions
at once, giving you a complete debugging experience with all Roslyn components.
If you're working on a specific area and want to optimize build times by deploying only the relevant extension, you can set one of the individual projects below as your startup project instead:
The experimental instance used by Roslyn is an entirely separate instance of Visual Studio with it's own settings and installed extensions. It's also, by default, a separate instance than the standard "Experimental Instance" used by other Visual Studio SDK projects. If you're familiar with the idea of Visual Studio hives, we deploy into the RoslynDev root suffix.
If you want to try your extension in your day-to-day use of Visual Studio, you can find the extensions you built in your Binaries folder with the .vsix extension. You can double-click the extension to install it into your main Visual Studio hive. This will replace the base installed version. Once it's installed, you'll see it marked as "Experimental" in Tools > Extensions and Updates to indicate you're running your experimental version. You can uninstall your version and go back to the originally installed version by choosing your version and clicking Uninstall.
If you only install the VSIX, then the IDE will behave correctly (ie. new compiler
and IDE behavior), but the Build operation or building from the command-line won't.
To fix that, add a reference to the Microsoft.Net.Compilers.Toolset you built into
your csproj. As shown below, you'll want to (1) add a nuget source pointing to your local build folder,
(2) add the package reference, then (3) verify the Build Output of your project with a
#error version included in your program.
See VSCode docs.
If you made changes to a Roslyn compiler and want to build any projects with it, you can either
use the Visual Studio hive where your CompilerExtension is installed, or from
command line, run msbuild with /p:BootstrapBuildPath=YourBootstrapBuildPath.
YourBootstrapBuildPath could be any directory on your machine so long as it had
csc and vbc inside it. You can check the cibuild.cmd and see how it is used.
To confirm what version of the compiler is being used, include #error version in your program
and the compiler will produce a diagnostic including its own version as well as the language
version it is operating under.
You can also attach a debugger to Visual Studio and check the loaded modules, looking at the folder
where the various CodeAnalysis modules were loaded from (the RoslynDev should load them somewhere
under AppData, not from Program File).
runtime repo as baseline (run build.cmd libs+libs.tests, which should be sufficient to build all C# code, installing any prerequisites if prompted to, and perhaps git clean -xdf and build.cmd -restore initially - see runtime repo documentation for specific prerequisites and build instructions)build.cmd -pack -c Release on your roslyn repo
-c Debug can also be used (along with changing Release to Debug in RestoreAdditionalProjectSources property value below). This will allow checking the compiler's debug assertions when building the runtime.%NUGET_PACKAGES%\microsoft.net.compilers.toolset or %userprofile%\.nuget\packages\microsoft.net.compilers.toolset).runtime similarly to this commit then build again
<RestoreAdditionalProjectSources><PATH-TO-YOUR-ROSLYN-ENLISTMENT>\artifacts\packages\Release\Shipping\</RestoreAdditionalProjectSources> using the local path to your roslyn repo to Directory.Build.props<UsingToolMicrosoftNetCompilers>true</UsingToolMicrosoftNetCompilers> and <MicrosoftNetCompilersToolsetVersion>5.3.0-dev</MicrosoftNetCompilersToolsetVersion> with the package version you just packed (look in above artifacts folder) to eng/Versions.propsSee internal documentation for that process here.
Run build.cmd -testIOperation which sets the ROSLYN_TEST_IOPERATION environment variable to true and runs the tests.
For running those tests in an IDE, the easiest is to find the //#define ROSLYN_TEST_IOPERATION directive and uncomment it.
See more details in the IOperation test hook doc.
In order to replicate test failures in that leg, there are a few options:
src/Compilers/Test/Core/Compilation/CompilationExtensions.cs:9, which defines ROSLYN_TEST_USEDASSEMBLIES, and run your tests. Do not check this in, as it
will enable the test hook for every test in every project and significantly slow down regular test runs.ROSLYN_TEST_USEDASSEMBLIES environment variable and restart VS with it set.CSharpTestBase.VerifyUsedAssemblyReferences in src/Compilers/Test/Utilities/CSharp/CSharpTestBase.cs. When it breaks, use VS's jump to location or
drag the instruction pointer past the early check and return on EnableVerifyUsedAssemblies.When a test failure is isolated, please add a dedicated test for this (ie. failing even when the Used Assemblies validation isn't enabled) to make it easier to avoid future regressions.
Preferrably, don't replicate the entire original test, just enough to hit the bug to ensure that it's protected against regressions.
Before pushing a relevant fix to CI, you can validate locally using the -testUsedAssemblies command-line option for build.cmd. For example: build.cmd -testCoreClr -testCompilerOnly -testUsedAssemblies.
Compilers.slnf. This is necessary to ensure the source generator project is built and we can load the generator assembly when running dotnet format.
C:\Source\roslyn> .\restore.cmd
C:\Source\roslyn> .\build.cmd
dotnet format (the one included in .NET SDK, not the global tool dotnet-format which is deprecated). Running only the analyzers subcommand and fixing only the "missing Public API signature" diagnostic. We must also pass the --include-generated flag to include source generated documents in the analysis.
C:\Source\roslyn> cd ..
C:\Source> dotnet format analyzers .\roslyn\Compilers.slnf --diagnostics=RS0016 --no-restore --include-generated -v diag
Please see Contributing Code for details on contributing changes back to the code.