Skip to content

Commit dade2c1

Browse files
authored
Merge branch 'csproj' into master
2 parents 3115359 + 839a839 commit dade2c1

14 files changed

+41
-522
lines changed

docs/core/getting-started.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ Install .NET Core on [Windows](https://www.microsoft.com/net/core#windows).
2121

2222
You can get started developing .NET Core apps by following these step-by-step tutorials.
2323

24-
* [Building a C# Hello World Application with .NET Core in Visual Studio 2017 RC](../csharp/getting-started/with-visual-studio-2017.md) - Learn to to build, debug, and publish a simple .NET Core console application using Visual Studio 2017 RC.
25-
* [Building a class library with C# and .NET Core in Visual Studio 2017 RC](../csharp/getting-started/library-with-visual-studio-2017.md) - Learn how to build a class library written in C# using Visual Studio 2017 RC
26-
* [Getting started with .NET Core on Windows, using Visual Studio 2015](tutorials/using-on-windows.md) - Learn how to use [Visual Studio](https://www.visualstudio.com/), the full-featured integrated development environment (IDE) for Windows, for different .NET Core scenarios.
24+
* [Building a C# Hello World Application with .NET Core in Visual Studio 2017](../csharp/getting-started/with-visual-studio-2017.md) - Learn to to build, debug, and publish a simple .NET Core console application using Visual Studio 2017.
25+
* [Building a class library with C# and .NET Core in Visual Studio 2017](../csharp/getting-started/library-with-visual-studio-2017.md) - Learn how to build a class library written in C# using Visual Studio 2017
2726
* [Get started with Visual Studio Code using C# and .NET Core on Windows](https://channel9.msdn.com/Blogs/dotnet/Get-started-with-VS-Code-using-CSharp-and-NET-Core) - This Channel9 video shows you how to install and use [Visual Studio Code](https://www.visualstudio.com/products/code-vs), Microsoft's lightweight cross-platform code editor, to create your first console application in .NET Core.
2827
* [Getting started with .NET Core on macOS, using Visual Studio Code](tutorials/using-on-macos.md) - This tutorial is mainly written for macOS, but you can follow the steps on Windows for a tour of the steps and workflow to create a .NET Core Solution using VS Code.
2928
* [Getting started with .NET Core using the command-line](tutorials/using-with-xplat-cli.md) - Use any code editor with the [.NET Core cross-platform command-line interface (CLI)](tools/index.md).
Lines changed: 3 additions & 266 deletions
Original file line numberDiff line numberDiff line change
@@ -1,272 +1,9 @@
11
---
2-
title: Getting started with .NET Core on Windows
3-
description: Getting started with .NET Core on Windows, using Visual Studio 2015
4-
keywords: .NET, .NET Core
5-
author: bleroy
6-
ms.author: mairaw
7-
ms.date: 06/20/2016
8-
ms.topic: article
9-
ms.prod: .net-core
10-
ms.devlang: dotnet
11-
ms.assetid: d743134a-08a3-4ff6-aab7-49f71f0568c3
2+
redirect_url: /dotnet/articles/csharp/getting-started/with-visual-studio-2017
123
---
134

145
# Getting started with .NET Core on Windows, using Visual Studio 2015
156

16-
> [!WARNING]
17-
> This topic applies to Visual Studio 2015 - .NET Core Tools Preview 2. For the Visual Studio 2017 RC - .NET Core Tools Preview 4 version,
18-
> see the [Getting started with .NET Core on Windows, using Visual Studio 2017](../preview3/tutorials/using-on-windows-vs-2017.md) topic.
19-
20-
Visual Studio 2015 provides a full-featured development environment for developing .NET Core applications. The procedures in this document describe the steps necessary to build a number of typical .NET Core solutions, or solutions that include .NET Core components, using Visual Studio. The scenarios include testing and using third-party libraries that have not been explicitly built for the most recent version of .NET Core.
21-
22-
## Prerequisites
23-
24-
Follow the instructions on [our prerequisites page](../windows-prerequisites.md) to update your environment.
25-
26-
## Getting Started
27-
28-
The following steps will set up Visual Studio 2015 for .NET Core development:
29-
30-
1. Open Visual Studio, and on the **File** menu, choose **New**, **Project**.
31-
32-
2. In the **New Project** dialog, in the **Templates** list, expand the **Visual C#** node and choose **.NET Core**. You should see three new project templates for **Class Library (.NET Core)**, **Console Application (.NET Core)**, and **ASP.NET Core Web Application (.NET Core)**.
33-
34-
A solution using only .NET Core projects
35-
----------------------------------------
36-
37-
### Writing the library
38-
39-
1. In Visual Studio, choose **File**, **New**, **Project**. In the **New Project** dialog, expand the **Visual C#** node and choose the **.NET Core** node, and then choose **Class Library (.NET Core)**.
40-
41-
2. Name the project "Library" and the solution "Golden". Leave **Create directory for solution** checked. Click **OK**.
42-
43-
3. In Solution Explorer, open the context menu for the **References** node and choose **Manage NuGet Packages**.
44-
45-
4. Choose "nuget.org" as the **Package source**, and choose the **Browse** tab. Browse for **Newtonsoft.Json**. Click **Install**.
46-
47-
5. Open the context menu for the **References** node and choose **Restore packages**.
48-
49-
6. Rename the `Class1.cs` file to `Thing.cs`. Accept the rename of the class. Remove the constructor and add a method: `public int Get(int number) => Newtonsoft.Json.JsonConvert.DeserializeObject<int>($"{number}");`
50-
51-
7. On the **Build** menu, choose **Build Solution**.
52-
53-
The solution should build without error.
54-
55-
### Writing the test project
56-
57-
1. In Solution Explorer, open the context menu for the **Solution** node and choose **Add**, **New Solution Folder**. Name the folder "test".
58-
This is only a solution folder, not a physical folder.
59-
60-
2. Open the context menu for the **test** folder and choose **Add**. **New Project**. In the **New Project** dialog, choose **Console Application (.NET Core)**. Name it "TestLibrary" and explicitly put it under the `Golden\test` path.
61-
62-
> [!IMPORTANT]
63-
> The project needs to be a console application, not a class library.
64-
65-
3. In the **TestLibrary** project, open the context menu for the **References** node and choose **Add Reference**.
66-
67-
4. In the **Reference Manager** dialog, check **Library** under the **Projects**, **Solution** node, and then click **OK**.
68-
69-
5. In the **TestLibrary** project, open the `project.json` file, and replace `"Library": "1.0.0-*"` with `"Library": {"target": "project", "version": "1.0.0-*"}`.
70-
71-
This is to avoid the resolution of the `Library` project to a NuGet package with the same name. Explicitly setting the target to "project" ensures that the tooling will first search for a project with that name, and not a package.
72-
73-
6. In the **TestLibrary** project, open the context menu for the **References** node and choose **Restore Packages**.
74-
75-
7. Open the context menu for the **References** node and choose **Manage NuGet Packages**.
76-
77-
8. Choose "nuget.org" as the **Package source**, and choose the **Browse** tab. Check the **Include prerelease** checkbox, and then browse for **xUnit** version 2.2.0 or newer, and then click **Install**.
78-
79-
9. Browse for **dotnet-test-xunit** version 2.2.0 or newer, and then click **Install**.
80-
81-
10. Edit `project.json` and replace `"imports": "dnxcore50"` with `"imports": [ "dnxcore50", "portable-net45+win8" ]`.
82-
83-
This enables the xunit libraries to be correctly restored and used by the project: those libraries have been compiled to be used with portable profiles that include "portable-net45+win8", but not .NET Core, which didn't exist when they were built. The `import` relaxes the tooling version checks at build time. You may now restore packages without error.
84-
85-
11. Edit `project.json` to add `"testRunner": "xunit",` after the `"frameworks"` section.
86-
87-
12. Add a `LibraryTests.cs` class file to the **TestLibrary** project, add the `using` directives `using Xunit;` and `using Library;` to the top of the file, and add the following code to the class:
88-
```csharp
89-
[Fact]
90-
public void ThingGetsObjectValFromNumber() {
91-
Assert.Equal(42, new Thing().Get(42));
92-
}
93-
```
94-
* Optionally, delete the `Program.cs` file from the **TestLibrary** project, and remove `"buildOptions": {"emitEntryPoint": true},` from `project.json`.
95-
96-
You should now be able to build the solution.
97-
98-
13. On the **Test** menu, choose **Windows**, **Test Explorer**, and in Test Explorer choose **Run All**.
99-
100-
The test should pass.
101-
102-
### Writing the console app
103-
104-
1. In Solution Explorer, open the context menu for the `src` folder, and add a new **Console Application (.NET Core)** project. Name it "App", and set the location to `Golden\src`.
105-
106-
2. In the **App** project, open the context menu for the **References** node and choose **Add**, **Reference**.
107-
108-
3. In the **Reference Manager** dialog, check **Library** under the **Projects**, **Solution** node, and then click **OK**
109-
110-
4. In the **App** project, open the `project.json` file, and replace `"Library": "1.0.0-*"` with `"Library": {"target": "project"}`.
111-
112-
5. Open the context menu for the **References** node and choose **Restore Packages**.
113-
114-
6. Open the context menu for the **App** node and choose **Set as StartUp Project**.
115-
116-
7. Open the `Program.cs` file, add a `using Library;` directive to the top of the file, and then add `Console.WriteLine($"The answer is {new Thing().Get(42)}");` to the `Main` method.
117-
118-
8. Set a breakpoint after the line that you just added.
119-
120-
9. Press F5 to run the application..
121-
122-
The application should build without error, and should hit the breakpoint. You should also be able to check that the application output "The answer is 42.".
123-
124-
A mixed .NET Core library and .NET Framework application
125-
--------------------------------------------------------
126-
127-
Starting from the solution obtained with the previous script, execute the following steps:
128-
129-
1. In Solution Explorer, open the `project.json` file for the **Library** project and replace `"frameworks": {
130-
"netstandard1.6" }` with `"frameworks": {
131-
"netstandard1.4" }`.
132-
133-
2. In the **Library** project, open the context menu for the **References** node and choose **Restore Packages**.
134-
135-
The solution should still build and function exactly like it did before: the test should pass, and the console application should run and be debuggable.
136-
137-
3. In the **Library** project, open the context menu and choose **Build**.
138-
139-
4. In Solution Explorer, open the context menu for the `src` folder, and choose **Add**. , **New Project**.
140-
141-
5. In the **New Project** dialog, choose the **Visual C#** node, and then choose **Console Application**.
142-
143-
> [!IMPORTANT]
144-
> Make sure you choose a standard console application, not the .NET Core version. In this section, you'll be consuming the library from a .NET Framework application.
145-
146-
6. Name the project "FxApp", and set the location to `Golden\src`.
147-
148-
7. In the **FxApp** project, open the context menu for the **References** node and choose **Add Reference**.
149-
150-
8. In the **Reference Manager** dialog, choose **Browse** and browse to the location of the built `Library.dll` (under the ..Golden\src\Library\bin\Debug\netstandard1.4 path), and then click **Add**.
151-
152-
You could also package the library and reference the package, as another way to reference .NET Core code from the .NET Framework.
153-
154-
9. Open the context menu for the **References** node and choose **Manage NuGet Packages**.
155-
156-
10. Choose "nuget.org" as the **Package source**, and choose the **Browse** tab. Check the **Include prerelease** checkbox, and then browse for **Newtonsoft.Json**. Click **Install**.
157-
158-
11. In the **FxApp** project, open the `Program.cs` file and add a `using Library;` directive to the top of the file, and add `Console.WriteLine($"The answer is {new Thing().Get(42)}.");` to the `Main` method of the program.
159-
160-
12. Set a breakpoint after the line that you just added.
161-
162-
13. Make **FxApp** the startup application for the solution.
163-
164-
14. Press F5 to run the app.
165-
166-
The application should build and hit the breakpoint. The application output should be "The answer is 42.".
167-
168-
> [!TIP]
169-
> On Windows platform you can use MSTest. Find out more in the [Using MSTest on Windows document](../testing/using-mstest-on-windows.md).
170-
171-
Moving a library from netstandard 1.4 to 1.3
172-
--------------------------------------------
173-
174-
1. In Solution Explorer, open the `project.json` file in the **Library** project.
175-
176-
2. Replace `frameworks": { "netstandard1.4" }` with `frameworks": { "netstandard1.3" }`.
177-
178-
3. In the **Library** project, open the context menu for the **References** node and choose **Restore Packages**.
179-
180-
4. On the **Build** menu, choose **Build Library**.
181-
182-
5. Remove the `Library` reference from the **FxApp** then add it back using the ..Golden\src\Library\bin\Debug\netstandard1.3 path. This will now reference the 1.3 version.
183-
184-
6. Press F5 to run the application.
185-
186-
Everything should still work as it did before. Check that the application output is "The answer is 42.", that the breakpoint was hit, and that variables can be inspected.
187-
188-
A mixed PCL library and .NET Framework application
189-
--------------------------------------------------
190-
191-
Close the previous solution if it was open: you will be starting a new script from this section on.
192-
193-
### Writing the library
194-
195-
1. In Visual Studio, choose **File**, **New**, **Project**. In the **New Project** dialog, expand the **Visual C#** node, and choose **Class Library (Portable for iOS, Android and Windows)**.
196-
197-
2. Name the project "PCLLibrary" and the solution "GoldenPCL". Leave **Create directory for solution** checked. Click **OK**.
198-
199-
3. In Solution Explorer, open the context menu for the **References** node and choose **Manage NuGet Packages**.
200-
201-
4. Choose "nuget.org" as the **Package source**, and choose the **Browse** tab. Check the **Include prerelease** checkbox, and then browse for **Newtonsoft.Json**. Click **Install**.
202-
203-
5. Rename the class "Thing" and add a method: `public int Get(int number) => Newtonsoft.Json.JsonConvert.DeserializeObject<int>($"{number}");`
204-
205-
6. On the **Build** menu, choose **Build Solution**, and verify that the solution builds.
206-
207-
### Writing the console app
208-
209-
1. In Solution Explorer, open the context menu for the **Solution 'GoldenPCL'** node and choose **Add**. **New Project**. In the **New Project** dialog, expand the **Visual C#** node, choose **Console Application**, and name the project "App".
210-
211-
2. In the **App** project, open the context menu for the **References** node and choose **Add**, **Reference**.
212-
213-
3. In the **Reference Manager** dialog, choose **Browse** and browse to the location of the built `PCLLibrary.dll` (under the ..\GoldenPCL\PCLLibrary\bin\Debug path), and then click **Add**.
214-
215-
4. In the **App** project, open the `Program.cs` file and add a `using PCLLibrary;` directive to the top of the file, and add `Console.WriteLine($"The answer is {new Thing().Get(42)}.");` to the `Main` method of the program.
216-
217-
5. Set a breakpoint after the line that you just added..
218-
219-
6. In Solution Explorer, open the context menu for the **App** node and choose **Set as StartUp Project**.
220-
221-
7. Press F5 to run the app.
222-
223-
The application should build, run, and hit the breakpoint after it outputs "The answer is 42.".
224-
225-
Moving a PCL to a NetStandard library
226-
-------------------------------------
227-
The Portable Class Library tooling can automatically modify your PCL to target .NET Standard.
228-
229-
1. Double click on the “Properties” node to open the Project Property page
230-
231-
2. Under the “Targeting header” click the hyperlink “Target .NET Platform Standard”
232-
233-
3. Click “Yes” when asked for confirmation
234-
235-
The tooling will automatically select the version of .NET Standard that includes all of the targets originally targeted by your PCL. You can target a different version of .NET Standard using the .NET Standard dropdown in the project property page.
236-
237-
* If you previously had a packages.config, you may be prompted to uninstall any installed packages before the conversion.
238-
239-
### Manually edit project.json to target .NET Standard from an existing Portable Class Library
240-
241-
1. If your project.json contains “dnxcore50” in the “supports” element, remove it.
242-
243-
2. Remove the dependency on “Microsoft.NETCore”
244-
245-
3. Modify the dependency on “Microsoft.NETCore.Portable.Compatibility” version “1.0.0” to version “1.0.1”
246-
247-
4. Add a dependency on “NETStandard.Library” version “1.6.0”
248-
249-
5. From the “frameworks” element, remove the “dotnet” framework (and the “imports” element within it)
250-
251-
6. Add ` "netstandard1.x” : { } ` to the frameworks element, where x is replaced with the version of .NET Standard you want to target
252-
253-
### Example project.json
254-
255-
This project.json includes supports clauses for UWP and .NET 4.6 and targets netstandard1.3:
256-
```
257-
{
258-
"supports": {
259-
"net46.app": {},
260-
"uwp.10.0.app": {},
261-
},
262-
"dependencies": {
263-
"NETStandard.Library": "1.6.0",
264-
"Microsoft.NETCore.Portable.Compatibility": "1.0.1"
265-
},
266-
"frameworks": {
267-
"netstandard1.3" : {}
268-
}
269-
}
270-
```
271-
7+
## Content retired!
2728

9+
For a getting started tutorial on .NET Core and Visual Studio 2017, see [(Building a C# Hello World application with .NET Core in Visual Studio 2017](../../csharp/getting-started/with-visual-studio-2017.md).

0 commit comments

Comments
 (0)