简体   繁体   English

体积映射 Visual Studio 2019 到 nuget package 缓存

[英]Volume mapping visual studio 2019 to nuget package cache

I don't use the inbuilt docker build inside of visual studio 2019 because it is too buggy.我不使用 Visual Studio 2019 内部的内置 docker 构建,因为它太麻烦了。 Instead I build my own container and then attach VS2019 to it for debugging.相反,我构建了自己的容器,然后将 VS2019 附加到它以进行调试。

If I make a change to a single dependency (or a previous layer) then it will re-download all dependencies in order to rebuild the needed layers.如果我对单个依赖项(或前一层)进行更改,那么它将重新下载所有依赖项以重建所需的层。

This is bandwidth/time intensive and the packages are already cached in local machine.这是带宽/时间密集型的,并且包已经缓存在本地机器中。

I have read: https://docs.microsoft.com/en-us/visualstudio/containers/container-build?view=vs-2019我已阅读: https://docs.microsoft.com/en-us/visualstudio/containers/container-build?view=vs-2019

It has interesting table explaining how the inbuilt feature maps folders:它有一个有趣的表格,解释了内置特征映射文件夹的方式:

在此处输入图像描述

How do I see what that mapping looks like?我如何查看该映射的外观? I think If I add that volume mapping to my own compose file then it would greatly increase speed as it wouldn't have to re-download on each build.我认为如果我将该卷映射添加到我自己的撰写文件中,那么它将大大提高速度,因为它不必在每次构建时重新下载。

In order to see what exactly your docker container is mapped to, you can list docker containers via为了查看您的 docker 容器到底映射到什么,您可以通过以下方式列出 docker 容器

docker ps

and then grab your containers id, and inspect it via然后获取您的容器 ID,并通过

docker inspect <id>

I have a container running right now which does use the inbuilt VS toolset, so let's see what that one says about mounts:我现在有一个正在运行的容器,它确实使用了内置的 VS 工具集,所以让我们看看它对挂载的看法:

...
        {
            "Type": "bind",
            "Source": "/host_mnt/c/Users/<name>/.nuget/packages",
            "Destination": "/root/.nuget/packages",
            "Mode": "ro",
            "RW": false,
            "Propagation": "rprivate"
        },
...

Okay, so this is the mount you're probably looking for.好的,这就是您可能正在寻找的坐骑。

In order to take a look at what VS does exactly, you can go to the 'obj' folder of your project, and then head to 'Docker'.为了看看 VS 究竟做了什么,你可以 go 到你项目的 'obj' 文件夹,然后前往 'Docker'。

In here you will find the actually interesting file VS will use for the docker-compose up call, which is eg the docker-compose.vs.debug.g.yml file.在这里,您会发现真正有趣的文件 VS 将用于docker-compose up调用,例如docker-compose.vs.debug.g.yml文件。 Here you will also find the release config, which does not contain the NuGet mount as it is actually building with dotnet publish .在这里,您还将找到发布配置,它不包含 NuGet 挂载,因为它实际上是使用dotnet publish构建的。

So in the docker-compose.vs.debug.g.yml file you can finally find the required path for the mount, which looks like this for my application:因此,在docker-compose.vs.debug.g.yml文件中,您终于可以找到挂载所需的路径,对于我的应用程序,如下所示:

    volumes:
  - ...
  - C:\Users\<name>\.nuget\packages\:/root/.nuget/packages:ro

Which is exactly what we found in the docker inspect.这正是我们在 docker 检查中发现的。

I hope this helps.我希望这有帮助。

Also, take a look at this article which goes into detail on how the whole docker setup VS uses works exactly:另外,看看这篇文章,它详细介绍了整个 docker 设置 VS 使用的工作原理:

https://www.scrum-tips.com/2017/12/27/understanding-docker-with-visual-studio-2017-part-2/ https://www.scrum-tips.com/2017/12/27/understanding-docker-with-visual-studio-2017-part-2/

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

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