简体   繁体   English

码头工人+ dotnet手表

[英]docker + dotnet watch

I use Visual studio Code. 我使用Visual Studio Code。

I create a new projet dotnet new webapi. 我创建一个新的projet dotnet和新的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> 我在.csproj中引用了dotnet-watch: <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. 然后,我构建我的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. 二进制文件已经在bin和obj目录中进行了更新,但是当我调用api时,就好像从未进行任何更改一样。

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 Docker命令:docker run -i -p 5000:5000 -v $ {pwd):/ app -t docker-todoapi

finally in the container terminal : docker restore and docker Watch run 终于在容器终端中:docker restore和docker watch run

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/ 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 . 使用Microsoft.DotNet.Watcher.Tools的 2.1.0-preview1-27567版本。

To get this preview version you need to add a NuGet.config file to your project directory: 要获得此预览版本,您需要在您的项目目录中添加一个NuGet.config文件:

<?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. Docker中使用的binobj目录必须与Visual Studio Code使用的目录分开,否则您将遇到当前遇到的问题。

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: 为此,必须将binobj目录放置在项目目录之外的一个相当奇怪的位置,这可以通过在项目目录中添加一个名为Directory.Build.props的文件来实现:

<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. 您还必须从项目目录中删除旧的binobj目录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM