geffback
geffback

Reputation: 1

docker + dotnet watch

I use Visual studio Code.

I create a new projet dotnet new webapi. I have referenced dotnet-watch in my .csproj : <ItemGroup> <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.Extensions.SecretManager.Tools" Version="2.0.0" /> <DotNetCliToolReference Include="Microsoft.Extensions.Caching.SqlConfig.Tools" Version="2.0.0" /> </ItemGroup>

Then, I Build my DockerFile.

I notice strange behavior. The docker image detects the changes and rebuilds the solution. The binary files have been updated in bin and obj directory but when I call the api, it is as if there had never been any change.

FROM microsoft/aspnetcore-build:2.0

COPY . /app
WORKDIR /app

ENV ASPNETCORE_URLS=http://*:5000
EXPOSE 5000

ENV DOTNET_USE_POLLING_FILE_WATCHER=1
ENV ASPNETCORE_ENVIRONMENT=Development

Docker command : docker run -i -p 5000:5000 -v $(pwd):/app -t docker-todoapi

finally in the container terminal : docker restore and docker Watch run

Upvotes: 0

Views: 1333

Answers (1)

Hallvar Helleseth
Hallvar Helleseth

Reputation: 1867

This blog post describes the current issues, but also how to get around the issues:

http://www.natemcmaster.com/blog/2017/11/13/dotnet-watch-and-docker/

To summarize changes you need:

Use version 2.1.0-preview1-27567 of Microsoft.DotNet.Watcher.Tools.

To get this preview version you need to add a NuGet.config file to your project directory:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="aspnetcore-nightly" value="https://dotnet.myget.org/F/aspnetcore-dev/api/v3/index.json" />
    <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

The bin and obj directories used in Docker must be separated from those used by Visual Studio Code, or you will have the problems you are currently seeing.

To do this the bin and obj directories must be placed in a rather odd place outside of the project directory, which can be accomplished by adding a file called Directory.Build.props to your project directory:

<Project>
  <PropertyGroup>
    <BaseIntermediateOutputPath>$(MSBuildProjectDirectory)/../obj/</BaseIntermediateOutputPath>
    <BaseOutputPath>$(MSBuildProjectDirectory)/../bin/</BaseOutputPath>
  </PropertyGroup>
</Project>

You must also delete the old bin and obj directories from your project directory.

Upvotes: 1

Related Questions