Skip to content

Commit 373af5d

Browse files
authored
Merge pull request #3552 from MicrosoftDocs/master636973419059797612
For protected CLA branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents 109bded + 174e3b7 commit 373af5d

File tree

9 files changed

+259
-41
lines changed

9 files changed

+259
-41
lines changed

docs/containers/container-build.md

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
---
2+
title: Visual Studio Container Tools build overview
3+
author: ghogen
4+
description: Overview of the Container Tools build process
5+
ms.author: ghogen
6+
ms.date: 06/06/2019
7+
ms.technology: vs-azure
8+
ms.topic: conceptual
9+
---
10+
# Building containerized apps using Visual Studio or the command line
11+
12+
Whether you're building from the Visual Studio IDE, or setting up a command-line build, you need to know how Visual Studio builds uses the Dockerfile to build your projects. For performance reasons, Visual Studio follows a special process for containerized apps. Understanding how Visual Studio builds your projects is especially important when you customize your build process by modifying the Dockerfile.
13+
14+
When Visual Studio builds a project that doesn't use Docker containers, it invokes MSBuild on the local machine and generates the output files in a folder (typically `bin`) under your local solution folder. For a containerized project, however, the build process takes account of the Dockerfile's instructions for building the containerized app. The Dockerfile that Visual Studio uses is divided into multiple stages. This process relies on Docker's *multistage build* feature.
15+
16+
## Multistage build
17+
18+
The multistage build feature helps make the process of building containers more efficient, and makes containers smaller by allowing them to contain only the bits that your app needs at runtime.
19+
20+
The multistage build allows container images to be created in stages that produce intermediate images. As an example, consider a typical Dockerfile generated by Visual Studio - the first stage is `base`:
21+
22+
```
23+
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2-stretch-slim AS base
24+
WORKDIR /app
25+
EXPOSE 80
26+
EXPOSE 443
27+
```
28+
29+
The lines in the Dockerfile begin with the Nanoserver image from Microsoft Container Registry (mcr.microsoft.com) and create an intermediate image `base` that exposes ports 80 and 443, and sets the working directory to `/app`.
30+
31+
The next stage is `build`, which appears as follows:
32+
33+
```
34+
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch AS build
35+
WORKDIR /src
36+
COPY ["WebApplication43/WebApplication43.csproj", "WebApplication43/"]
37+
RUN dotnet restore "WebApplication43/WebApplication43.csproj"
38+
COPY . .
39+
WORKDIR "/src/WebApplication43"
40+
RUN dotnet build "WebApplication43.csproj" -c Release -o /app
41+
```
42+
43+
You can see that the `build` stage starts from a different original image from the registry (`sdk` rather than `aspnet`), rather than continuing from base. The `sdk` image has all the build tools, and for that reason it's a lot bigger than the aspnet image, which only contains runtime components. The reason for using a separate image becomes clear when you look at the rest of the Dockerfile:
44+
45+
```
46+
FROM build AS publish
47+
RUN dotnet publish "WebApplication43.csproj" -c Release -o /app
48+
49+
FROM base AS final
50+
WORKDIR /app
51+
COPY --from=publish /app .
52+
ENTRYPOINT ["dotnet", "WebApplication43.dll"]
53+
```
54+
55+
The final stage starts again from `base`, and includes the `COPY --from=publish` to copy the published output to the final image. This process makes it possible for the final image to be a lot smaller, since it doesn't need to include all of the build tools that were in the `sdk` image.
56+
57+
## Faster builds for the Debug configuration
58+
59+
For performance reasons, the build process for containerized apps is not as straightforward as simply following the steps outlined in the Dockerfile. Building in a container is much slower than building on the local machine. So, when you build in the **Debug** configuration, Visual Studio actually builds your projects on the local machine, and then shares the output folder to the container using volume mounting. A build with this optimization enabled is called a *Fast* mode build.
60+
61+
In **Fast** mode, Visual Studio calls `docker build` with an argument that tells Docker to build only the `base` stage. Visual Studio handles the rest of the process without regard to the contents of the Dockerfile. So, when you modify your Dockerfile, such as to customize the container environment or install additional dependencies, you should put your modifications in the first stage. Any custom steps placed in the Dockerfile's `build`, `publish`, or `final` stages will not be executed.
62+
63+
This performance optimization only occurs when you build in the **Debug** configuration. In the **Release** configuration, the build occurs in the container as specified in the Dockerfile.
64+
65+
If you want to disable the performance optimization and build as the Dockerfile specifies, then set the **ContainerDevelopmentMode** property to **Regular** in the project file as follows:
66+
67+
```xml
68+
<PropertyGroup>
69+
<ContainerDevelopmentMode>Regular</ContainerDevelopmentMode>
70+
</PropertyGroup>
71+
```
72+
73+
To restore the performance optimization, set the value to **Fast**.
74+
75+
## Building from the command line
76+
77+
You can use `docker build` or `MSBuild` to build from the command line.
78+
79+
### docker build
80+
81+
To build a containerized solution from the command line, you can usually use the command `docker build <context>` for each project in the solution. You provide the *build context* argument. The *build context* for a Dockerfile is the folder on the local machine that's used as the working folder to generate the image. For example, it's the f`older that you copy files from when you copy to the container. In .NET Core projects, use the folder that contains the solution file (.sln). Expressed as a relative path, this argument is typically ".." for a Dockerfile in a project folder, and the solution file in its parent folder. For .NET Framework projects, the build context is the project folder, not the solution folder.
82+
83+
> [!NOTE]
84+
> For .NET Framework projects, and for .NET Core projects created with versions of Visual Studio prior to Visual Studio 2017 Update 4, the Dockerfile did not use multistage builds. When Visual Studio builds with these Dockerfiles, instead of building the project in the Dockerfile, Visual Studio builds each project and then copies the results to the container. Because the build steps aren't included in the Dockerfile, you can't build such projects using `docker build` from the command line. You should use MSBuild to build these projects.
85+
86+
### MSBuild
87+
88+
To build a project or solution for single docker container, you can use MSBuild with the `/t:ContainerBuild` command option.
89+
90+
```cmd
91+
MSBuild <solution_name>.sln /t:ContainerBuild /p:Configuration=Debug
92+
```
93+
94+
You'll see output similar to what you see in the **Output** window when you build your solution from the Visual Studio IDE.
95+
96+
When the **Debug** configuration is specified (and the **ContainerDevelopmentMode** property is set to **Fast**), Visual Studio uses the build optimization described in this article, so your project builds more quickly on the local machine and is copied to the container. When the **Release** configuration is specified, the build occurs in the container and might be slower.
97+
98+
If you are using a Docker Compose project, use the command:
99+
100+
```
101+
msbuild /t:DockerPackageService /p:DockerAppType=AspNet /p:Configuration=Release <project_name>\<project_name>.csproj
102+
msbuild /p:Configuration=Release docker-compose.dcproj
103+
```
104+
105+
## Scripting a containerized build using Azure DevOps
106+
107+
You can use Azure Pipelines to build your containerized apps and publish to Azure Container Registry or Docker Hub. Follow the instructions for setting up an Azure Pipeline in this article: [Build, test, and push Docker container app](/azure/devops/pipelines/languages/docker?view=azure-devops). However, to build your solution, add an MSBuild task to your pipeline. Internally, MSBuild uses `docker build` to build your containers.
108+
109+
Add an MSBuild task to your pipeline as follows:
110+
111+
```
112+
- task: MSBuild@1
113+
displayName: 'Build Application and main Docker Image'
114+
inputs:
115+
solution: '**/*.sln'
116+
msbuildArguments: '/t:ContainerBuild /p:Configuration=$(buildConfiguration)'
117+
```
118+
119+
For more information, see [MSBuild task](/azure/devops/pipelines/tasks/build/msbuild?view=azure-devops).
120+
121+
## Next steps
122+
123+
Learn how to further customize your builds by setting additional MSBuild properties in your project files. See [Container Tools build properties](container-msbuild-properties.md).
124+
125+
## See also
126+
127+
[MSBuild](../msbuild/msbuild.md)
128+
[Dockerfile on Windows](/virtualization/windowscontainers/manage-docker/manage-windows-dockerfile)
129+
[Linux containers on Windows](/virtualization/windowscontainers/deploy-containers/linux-containers)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Visual Studio Container Tools build properties
3+
author: ghogen
4+
description: Overview of the Container Tools build process
5+
ms.author: ghogen
6+
ms.date: 06/06/2019
7+
ms.technology: vs-azure
8+
ms.topic: conceptual
9+
---
10+
# Container Tools build properties
11+
12+
You can customize how Visual Studio builds your container projects by setting the properties that MSBuild uses to build your project. For example, you can change the name of the Dockerfile, specify tags and labels for your images, provide additional arguments passed to Docker commands, and control whether Visual Studio does certain performance optimizations such as building outside of the container environment. You can also set debugging properties such as the name of the executable to launch, and the command line arguments to provide.
13+
14+
To set the value of a property, edit the project file. For example, suppose your Dockerfile is named *MyDockerfile*. You can set the `DockerfileFile` property in the project file as follows.
15+
16+
```xml
17+
<PropertyGroup>
18+
<DockerfileFile>MyDockerfile</DockerfileFile>
19+
</PropertyGroup>
20+
```
21+
22+
You can add the property setting to an existing `PropertyGroup` element, or if there isn't one, create a new `PropertyGroup` element.
23+
24+
The following table shows the MSBuild properties available for container projects.
25+
26+
| Property name | Description | Default value |
27+
|---------------|-------------|----------------|
28+
| DockerfileFile | Describes the default Dockerfile that will be used to build/run the container for the project. This can be a path as well. | Dockerfile |
29+
| DockerfileTag | The tag that will be used when building the Docker image. In debugging, a ":dev" is appended to the tag. | Assembly name after stripping non-alphanumeric characters with the following rules: <br/> If the resultant tag is all numeric, then "image" is inserted as a prefix (for example, image2314) <br/> If the resultant tag is an empty string, then "image" is used as the tag. |
30+
| DockerContext | The default context used when building the Docker image. | Set by Visual Studio. |
31+
| ContainerDevelopmentMode | Controls whether "build-on-host" optimization ("Fast Mode" debugging) is enabled. Allowed values are **Fast** and **Regular**. | Fast |
32+
| DockerDefaultTargetOS | The default target operating system used when building the Docker image. | Set by Visual Studio. |
33+
| DockerImageLabels | The default set of labels applied to the Docker image. | com.microsoft.created-by=visual-studio;com.microsoft.visual-studio.project-name=$(MSBuildProjectName) |
34+
| ContainerVsDbgPath | The path for VSDBG debugger. | `%USERPROFILE%\vsdbg\vs2017u5` |
35+
| DockerfileBuildArguments | Additional arguments passed to the Docker build command. | Not applicable. |
36+
| DockerfileRunArguments | Additional arguments passed to the Docker run command. | Not applicable. |
37+
| DockerfileRunEnvironmentFiles | Semicolon-delimited list of environment files applied during Docker run. | Not applicable. |
38+
| DockerfileFastModeStage | The Dockerfile stage (that is, target) to be used when building the image in debug mode. | First stage found in the Dockerfile (base) |
39+
| DockerDebuggeeProgram | When debugging, the debugger is instructed to launch this executable. | For .NET Core projects: dotnet, ASP.NET .NET Framework projects: Not applicable (IIS is always used) |
40+
| DockerDebuggeeArguments | When debugging, the debugger is instructed to pass these arguments to the launched executable. | Not applicable to ASP.NET .NET Framework projects |
41+
| DockerDebuggeeWorkingDirectory | When debugging, the debugger is instructed to use this path as the working directory. | C:\app (Windows) or /app (Linux) |
42+
| DockerDebuggeeKillProgram | This command is used to kill the running process in a container. | Not applicable to ASP.NET .NET Framework projects |
43+
44+
## Next steps
45+
46+
For information on MSBuild properties generally, see [MSBuild Properties](../msbuild/msbuild-properties.md).
47+
48+
## See also
49+
50+
[MSBuild reserved and well-known properties](../msbuild/msbuild-reserved-and-well-known-properties.md).

docs/containers/container-tools-react.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to use Visual Studio Container Tools and Docker for Windo
55
ms.author: ghogen
66
ms.date: 06/06/2019
77
ms.technology: vs-azure
8-
ms.topic: include
8+
ms.topic: quickstart
99
---
1010
# Quickstart: Use Docker with a React Single-page App in Visual Studio
1111

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
title: Unit test a containerized app
3+
author: ghogen
4+
description: Run unit tests with every build for a Docker project in Visual Studio
5+
ms.author: ghogen
6+
ms.date: 06/17/2019
7+
ms.technology: vs-azure
8+
ms.topic: conceptual
9+
---
10+
# How to: Run unit tests for a containerized app
11+
12+
You can run unit tests with every build of your containerized project by modifying your Dockerfile.
13+
14+
## Prerequisites
15+
16+
- [Docker Desktop](https://hub.docker.com/editions/community/docker-ce-desktop-windows)
17+
- Install [Visual Studio 2019](https://visualstudio.microsoft.com/downloads/?utm_medium=microsoft&utm_source=docs.microsoft.com&utm_campaign=inline+link&utm_content=download+vs2019)
18+
- Unit tests set up to run using [dotnet test](/dotnet/core/tools/dotnet-test)
19+
- Install the [Containers window extension](https://aka.ms/vscontainerspreview)
20+
21+
## Add unit tests to the Dockerfile
22+
23+
Visual Studio does some special performance optimizations before modifying the Dockerfile. When building the **Debug** configuration, Visual Studio builds projects on the local machine, and copies the results to the container. So, only the first stage of the multistage Dockerfile is executed as specified in the Dockerfile. For more information, see [Container Tools build process for Visual Studio](container-build.md).
24+
25+
To add unit tests to a multistage Dockerfile, add a `unit-test` stage to the Dockerfile between the `build` and `publish` stages.
26+
27+
```
28+
FROM build AS unit-test
29+
RUN dotnet unit-test --logger:trx
30+
```
31+
32+
Visual Studio only runs the first stage in **Debug** configuration, so the `unit-test` stage is only run in the **Release** configuration. But even in **Release** configuration, the log results won't be included in the final image, because the final image is built from the `base` stage, not from the `unit-test` stage. To run the tests and produce an image where you can view the logs, use the following command:
33+
34+
```cmd
35+
docker build --target:unit-test
36+
```
37+
38+
## Next steps
39+
40+
You can then use the [Containers window](view-and-diagnose-containers.md) (if you have the extension installed) to view the test logs.
41+
42+
To view your test logs, use **Ctrl**+**Q** and search for **Containers** to open the **Containers** window. In the **Containers** window, find your container, open the **Files** tab, look for your test results (.trx) file in the container's filesystem, and open it to view the results in Visual Studio.
43+

docs/containers/edit-and-refresh.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ When using .NET Framework console app projects, the option to add Docker support
115115

116116
![Breakpoint](media/edit-and-refresh/breakpoint-console.png)
117117

118+
## Container reuse
119+
120+
During the development cycle, Visual Studio only rebuilds your container images and the container itself when you change the Dockerfile, but if not, it reuses the container from a previous run.
121+
122+
If you manually modified your container and want to restart from a clean container image, use the **Build** > **Clean** command in Visual Studio, and then build as normal.
123+
118124
## Summary
119125

120126
With Docker support in Visual Studio, you can get the productivity of working locally,

docs/containers/toc.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,16 @@
3030
href: view-and-diagnose-containers.md
3131
- name: Configure Container Tools
3232
href: container-tools-configure.md
33+
- name: Run unit tests
34+
href: container-unit-testing.md
35+
- name: Concepts
36+
items:
37+
- name: Building containerized apps
38+
href: container-build.md
3339
- name: Troubleshooting
3440
href: troubleshooting-docker-errors.md
41+
- name: Reference
42+
items:
43+
- name: MSBuild properties for container projects
44+
href: container-msbuild-properties.md
45+

mac/snippets.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ There are two reserved keywords that you can use in a snippet:
8181

8282
The `for` snippet in the previous section is an example of both these reserved keywords.
8383

84-
Refer to the [Visual Studio code snippets reference](/visualstudio/ide/code-snippets-schema-reference#keywords) for more information.
85-
8684
## See also
8785

8886
- [Code snippets (Visual Studio on Windows)](/visualstudio/ide/code-snippets)

subscriptions/vscloud-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ You can buy [Visual Studio Professional and Visual Studio Enterprise subscriptio
2222
* To bill your purchases, you need an [Azure subscription](https://azure.microsoft.com/pricing/purchase-options/). You can [sign up](https://portal.azure.com) before your first purchase or during your first purchase in the Visual Studio Marketplace.
2323

2424
## Who can buy Visual Studio cloud subscriptions?
25-
Anyone with [owner and contributor access](https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fvsts%2Forganizations%2Fbilling%2Fadd-backup-billing-managers%3Fview%3Dvsts%2520%2520sa&data=02%7C01%7C%7Cb9e717e8abff47b0cd7e08d618edd860%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C636723807145220358&sdata=aIaamEXHhx94KCYVY%2FFibqFzNBEqKPntpql867xAMgU%3D&reserved=0) to the Azure subscription can purchase cloud subscriptions.
25+
Anyone with [owner](https://docs.microsoft.com/azure/role-based-access-control/built-in-roles#owner), [service admin](https://docs.microsoft.com/azure/billing/billing-add-change-azure-subscription-administrator#change-the-service-administrator-for-an-azure-subscription), or [co-admin](https://docs.microsoft.com/azure/billing/billing-add-change-azure-subscription-administrator#add-or-change-co-administrator) access to the Azure subscription can purchase cloud subscriptions.
2626

2727
## How to buy cloud subscriptions
2828

0 commit comments

Comments
 (0)