Building, Debugging, and Testing on Windows.md 7.8 KB
Newer Older
J
Jared Parsons 已提交
1
# Building, Debugging and Testing on Windows
2

J
Jared Parsons 已提交
3
## Working with the code
4

J
Jared Parsons 已提交
5
Using the command line Roslyn can be developed using the following pattern:
6

J
Jared Parsons 已提交
7
1. Clone https://github.com/dotnet/roslyn
A
Andrew Arnott 已提交
8
1. Run Restore.cmd
J
Jared Parsons 已提交
9
1. Run Build.cmd
J
Fixup  
Jared Parsons 已提交
10
1. Run Test.cmd
11

T
Tomas Matousek 已提交
12 13
## Recommended version of .NET Framework

J
Jared Parsons 已提交
14
The minimal required version of .NET Framework is 4.7.2.
T
Tomas Matousek 已提交
15

J
Jared Parsons 已提交
16
## Developing with Visual Studio 2019
T
Tomas Matousek 已提交
17

J
Jared Parsons 已提交
18
1. [Visual Studio 2019 RC](https://visualstudio.microsoft.com/downloads/#2019rc)
J
Jared Parsons 已提交
19
    - Ensure C#, VB, MSBuild, .NET Core and Visual Studio Extensibility are included in the selected work loads
J
Jared Parsons 已提交
20
    - Ensure Visual Studio is on Version "RC1" or greater
21
1. [.NET Core SDK 2.1.401](https://www.microsoft.com/net/download/core) (the installers are: [Windows x64 installer](https://dotnetcli.blob.core.windows.net/dotnet/Sdk/2.1.401/dotnet-sdk-2.1.401-win-x64.exe), [Windows x86 installer](https://dotnetcli.blob.core.windows.net/dotnet/Sdk/2.1.401/dotnet-sdk-2.1.401-win-x86.exe))
N
Nick Kirby 已提交
22
1. [PowerShell 5.0 or newer](https://docs.microsoft.com/en-us/powershell/scripting/setup/installing-windows-powershell). If you are on Windows 10, you are fine; you'll only need to upgrade if you're on Windows 7. The download link is under the "upgrading existing Windows PowerShell" heading.
J
Fixup  
Jared Parsons 已提交
23
1. Run Restore.cmd
J
Jared Parsons 已提交
24
1. Open Roslyn.sln
25

J
Jared Parsons 已提交
26
If you already installed Visual Studio and need to add the necessary work loads or move to Preview 4:
J
Jared Parsons 已提交
27
do the following:
28

29
- Run the Visual Studio Installer from your start menu. You can just search for "Visual Studio Installer". If you can't find it, it's typically located at "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installer.exe"
J
Fixup  
Jared Parsons 已提交
30
- The Visual Studio installation will be listed under the Installed section
A
Andrew Arnott 已提交
31
- Click on the menu icon (three horizontal lines), click Modify
J
Fixup  
Jared Parsons 已提交
32
- Choose the workloads listed above and click Modify
J
Jared Parsons 已提交
33 34 35

## Running Tests

J
Jason Malinowski 已提交
36
There are a number of options for running the core Roslyn unit tests:
37

J
Jared Parsons 已提交
38 39
### Command Line

A
Andrew Arnott 已提交
40
The Test.cmd script will run our unit test on already built binaries.  It can be passed the -build arguments to force a new build before running tests.
J
Jared Parsons 已提交
41

J
Jared Parsons 已提交
42
1. Run the "Developer Command Prompt for VS2019" from your start menu.
43
2. Navigate to the directory of your Git clone.
J
Jonathon Marolf 已提交
44
3. Run `msbuild /v:m /m /nodereuse:false BuildAndTest.proj` in the command prompt.
45

46
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.
47 48 49

The results of the tests can be viewed in the artifacts/TestResults directory.

A
Andrew Arnott 已提交
50
### Test Explorer
51 52 53 54 55 56 57 58 59 60 61

Tests can be run and debugged from the Test Explorer window. For best performance, we recommend the following:

1. Open **Tools → Options... → Test**
    1. Check the box for **Discover tests in real time from source files**
    2. Uncheck the box for **Additionally discover tests from build assemblies...**
2. Use the Search box of Test Explorer to narrow the scope of visible tests to the feature(s) you are working on
3. When you are not actively running tests, set the search query to `__NonExistent__` to hide all tests from the UI

### WPF Test Runner

62 63 64 65 66 67 68 69
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](https://github.com/pilchie/xunit.runner.wpf), build it and
give it a try.

J
Jared Parsons 已提交
70 71 72
## Trying Your Changes in Visual Studio

The Rosyln solution is designed to support easy debugging via F5.  Several of our
A
Andrew Arnott 已提交
73
projects produce VSIX which deploy into Visual Studio during build.  The F5 operation
J
Fixup  
Jared Parsons 已提交
74
will start a new Visual Studio instance using those VSIX which override our installed
75
binaries.  This means trying out a change to the language, IDE or debugger is as
J
Jared Parsons 已提交
76
simple as hitting F5.
77

A
Andrew Arnott 已提交
78
The startup project needs to be set to `RoslynDeployment`.  This should be
79
the default but in same cases will need to be set explicitly.
80 81 82

Here are what is deployed with each extension, by project that builds it. If
you're working on a particular area, you probably want to set the appropriate
A
Andrew Arnott 已提交
83
project as your startup project to optimize building and deploying only the relevant bits.
84

A
Andrew Arnott 已提交
85
- **Roslyn.VisualStudio.Setup**: this project can be found inside the VisualStudio folder
P
Paul Chen 已提交
86
  from the Solution Explorer, and builds Roslyn.VisualStudio.Setup.vsix. It
87 88 89 90 91
  contains the core language services that provide C# and VB editing. It also
  contains the copy of the compiler that is used to drive IntelliSense and
  semantic analysis in Visual Studio. Although this is the copy of the compiler
  that's used to generate squiggles and other information, it's not the
  compiler used to actually produce your final .exe or .dll when you do a
J
Jason Malinowski 已提交
92 93
  build. If you're working on fixing an IDE bug, this is the project you want
  to use.
A
Andrew Arnott 已提交
94 95 96 97
- **Roslyn.VisualStudio.InteractiveComponents**: this project can be found in the
  Interactive\Setup folder from the Solution Explorer, and builds
  Roslyn.VisualStudio.InteractiveComponents.vsix.
- **Roslyn.Compilers.Extension**: this project can be found inside the Compilers\Packages folder
P
Paul Chen 已提交
98
  from the Solution Explorer, and builds Roslyn.Compilers.Extension.vsix.
99 100 101 102 103 104 105 106
  This deploys a copy of the command line compilers that are used to do actual
  builds in the IDE. It only affects builds triggered from the Visual Studio
  experimental instance it's installed into, so it won't affect your regular
  builds. Note that if you install just this, the IDE won't know about any
  language features included in your build. If you're regularly working on new
  language features, you may wish to consider building both the
  CompilerExtension and VisualStudioSetup projects to ensure the real build and
  live analysis are synchronized.
P
Paul Chen 已提交
107 108 109
- **ExpressionEvaluatorPackage**: this project can be found inside the
  ExpressionEvaluator\Setup folder from the Solution Explorer, and builds
  ExpressionEvaluatorPackage.vsix. This deploys the expression evaluator and
110
  result providers, the components that are used by the debugger to parse and
111
  evaluate C# and VB expressions in the Watch window, Immediate window, and
112 113 114 115 116 117 118 119 120
  more. These components are only used when debugging.

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
121 122 123 124 125
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
J
Jason Malinowski 已提交
126 127
your version and go back to the originally installed version by choosing your
version and clicking Uninstall.
128

P
Paul Chen 已提交
129
If you made changes to a Roslyn compiler and want to build any projects with it, you can either
P
Paul Chen 已提交
130 131 132
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
P
Paul Chen 已提交
133
csc and vbc inside it. You can check the cibuild.cmd and see how it is used.
P
Paul Chen 已提交
134

J
Jared Parsons 已提交
135
## Contributing
136

137
Please see [Contributing Code](https://github.com/dotnet/roslyn/blob/master/CONTRIBUTING.md) for details on contributing changes back to the code.