VS 2022 + .Net 6.0 如何设置nuget的package路径为当前解决方案路径?

howze 2023-01-30 09:12:39

之前使用.net framwork框架的时候,使用nuget安装各种库会自动在当前解决方案文件夹下生成一个packages文件夹。

下载的库都在这个里面,项目引用的路径也在这个里面。

但是将平台切换到.net 6.0 后,发现这个包packages默认在C盘。

网上找了很多帖子,确实可以改这个路径,但都是固定路径,不能跟着解决方案走。

就是当使用.net 6.0平台的时候无法实现自动在当前解决方案文件夹下生成packages文件夹并将nuget的包下载到这里

不知道我表达清楚没有,各位是咋解决这个问题的?

谢谢!

...全文
1905 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
morliz子轩 2023-02-03
  • 打赏
  • 举报
回复 1

原来只需要在解决方案文件csproj中添加:

<RestorePackagesPath>..\packages</RestorePackagesPath>

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <MvcRazorCompileOnPublish>false</MvcRazorCompileOnPublish>
    <RestorePackagesPath>..\packages</RestorePackagesPath>
  </PropertyGroup>

</Project>

这样就在项目中了,分享给你。

howze 2023-02-24
  • 举报
回复
@morliz子轩 感谢分享,我来试试看。
morliz子轩 2023-02-03
  • 打赏
  • 举报
回复

这个问题是个好问题,我也在苦恼这个。搞在C盘,package包已经4个多G了。不查不知道,一查吓一跳

赵4老师 2023-01-31
  • 打赏
  • 举报
回复

仅供参考
d:>nuget
NuGet Version: 5.10.0.7240
usage: NuGet [args] [options]
Type 'NuGet help ' for help on a specific command.
Available commands:
add Adds the given package to a hierarchical source. http sources are not supported. For more info, goto http
s://docs.nuget.org/consume/command-line-reference#add-command.
client-certs Provides the ability to manage list of client certificates located in NuGet.config files
config 获取或设置 NuGet 配置值。
delete 从服务器中删除程序包。
help (?) 显示一般帮助信息,以及有关其他命令的帮助信息。
init Adds all the packages from the to the hierarchical . http f
eeds are not supported. For more info, goto https://docs.nuget.org/consume/command-line-reference#init-co
mmand.
install 使用指定的源安装程序包。如果未指定源,则将使用 NuGet 配置文件中定义的所有源。如果配置文件未指定源,则使用
默认的 NuGet 源。
list 显示给定源中的程序包列表。如果未指定源,则使用 %AppData%\NuGet\NuGet.config 中定义的所有源。如果 NuGet.co
nfig 未指定源,则使用默认 NuGet 源。
locals Clears or lists local NuGet resources such as http requests cache, temp cache or machine-wide global pack
ages folder.
pack 基于指定的 nuspec 或项目文件创建 NuGet 程序包。
push 将程序包推送到服务器并进行发布。
通过加载 %AppData%\NuGet\NuGet.config,然后加载从驱动器的根目录开始到当前目录为止的任何 nuget.config 或 .
nuget\nuget.config 来获取 NuGet 的
默认配置。
restore 还原 NuGet 程序包。
search Searches a given source using the query string provided. If no sources are specified, all sources defined
in %AppData%\NuGet\NuGet.config are used.
setApiKey 保存给定服务器 URL 所对应的 API 密钥。如果未提供 URL,则保存 NuGet 库的 API 密钥。
sign Signs a NuGet package with the specified certificate.
sources 可以管理位于 %AppData%\NuGet\NuGet.config 的源列表
spec 为新程序包生成 nuspec。如果此命令在项目文件(.csproj、.vbproj、.fsproj)所在的文件夹中运行,则它将创建已标
记化的 nuspec 文件。
trusted-signers Provides the ability to manage the list of trusted signers.
update 将程序包更新到最新的可用版本。此命令还更新 NuGet.exe 本身。
verify Verifies a signed NuGet package.
有关详细信息,请访问 https://docs.nuget.org/docs/reference/command-line-reference

111,088

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧