将包文件夹移动到解决方案文件夹中 [英] Move packages folder inside the solution folder

查看:70
本文介绍了将包文件夹移动到解决方案文件夹中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio 2017/ASP.NET Web 应用程序解决方案.

Visual Studio 2017 / ASP.NET Web Application solution.

默认文件夹结构如下:

我想要实现的是将所有内容(包括包)保存在 WebApplication1 文件夹中(WebApplication1.sln 文件除外).

What I want to achieve is keeping everything (including packages) inside the WebApplication1 folder (except WebApplication1.sln file).

我知道 NuGet.Config,但不幸的是,似乎必须将此文件放在 .sln 文件旁边.我更希望将此文件放在 WebApplication1 文件夹中.我想要解决方案文件夹之外的只有一个文件:WebApplication1.sln 文件.

I know about NuGet.Config but unfortunately it seems mandatory to place this file next to the .sln file. I would have preferred to place this file inside of WebApplication1 folder. I would like to have ONLY ONE file outside of the solution folder: the WebApplication1.sln file.

推荐答案

我知道 NuGet.Config 但不幸的是,似乎必须将此文件放在 .sln 文件旁边.我更愿意将此文件放在 WebApplication1 文件夹中.我想要解决方案文件夹之外只有一个文件:WebApplication1.sln 文件.

I know about NuGet.Config but unfortunately it seems mandatory to place this file next to the .sln file. I would have preferred to place this file inside of WebApplication1 folder. I would like to have ONLY ONE file outside of the solution folder: the WebApplication1.sln file.

我了解您的要求,您只想在解决方案文件夹之外拥有 WebApplication1.sln 文件.但是如果你使用 nuget.config 来改变包的位置,这个 nuget.config 文件会放在解决方案文件夹之外的一个文件夹中,这不是你的想要.

I understand your requirement, you want to have only WebApplication1.sln file outside of the solution folder. But if you are using nuget.config to change the location of packages, this nuget.config file will be placed in a folder outside the solution folder, which is not what you want.

要解决这个问题,你可以把这个nuget.config文件放在解决方案文件夹之外,不需要把这个文件放在.sln文件旁边,比如你可以把这个文件放在C盘根目录下,内容如下:

To resolve this issue, you can put this nuget.config file outside the solution folder, which is not necessary to put this file next to the .sln file, for example, you can put this file in the root directory of the C drive with following content:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="C:\Users\<UserName>\source\repos\WebApplication1\WebApplication1\packages" />
  </config>
</configuration>

然后关闭您的Visual Studio并删除解决方案文件夹中的packages文件夹,重新打开Visual Studio并打开您的解决方案,右键单击您的解决方案,选择恢复nuget包,所有nuget包都会被放置解决方案文件夹内和解决方案文件夹外的唯一文件是 WebApplication1.sln 文件:

Then close your Visual Studio and delete the packages folder in the solution folder, re-open the Visual Studio and open the your solution, right click on the your solution, select restore the nuget packages, all the nuget packages will be place inside the solution folder and the only file outside of the solution folder is the WebApplication1.sln file:

注意:此方法有其自身的局限性,我们必须在 nuget.config 文件中使用绝对路径,此设置仍适用于其他解决方案.

Note: This method has its own limitations, we have to use absolute path in the nuget.config file and this setting will still be work for other solutions.

此外,您可以尝试在项目文件中使用 PackageReference 而不是 packages.config.使用PackageReference,你的包指向全局包文件夹C:\Users\\.nuget\packages,这样我们就不需要添加nuget.config 文件来更改包文件夹.

Besides, you can try to use PackageReference instead of packages.config in project files. With PackageReference, your packages are point to the global package folder C:\Users\<UserName>\.nuget\packages, so that we do not need add a nuget.config file to change the package folder.

要使用 PackageReference,请转到 Tools->NuGet PackageManager->Package Manage Settings:

To use the PackageReference, go to the Tools->NuGet PackageManager->Package Manage Settings:

希望这会有所帮助.

这篇关于将包文件夹移动到解决方案文件夹中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆