我可以制作一个Visual Studio解决方案文件以自动下载Nuget软件包吗?
我正在学习如何使用Visual Studio并发布/消费Nuget软件包。遵循以下教程之后:
https:> https:// .com/en-us/nuget/overume-packages/概述和工作流
我可以创建一个简单的nuget软件包并发布/构建良好,并找到所得的.csproj项目文件。
我被分配的一项任务是创建一个将自动下载Nuget软件包的Visual Studios解决方案文件,但我还没有在Nuget文档中看到此内容。
如何为Visual Studio 2019创建一个解决方案文件(或项目文件?),以使任何用户可以使用(运行?)与他们的项目一起使用此文件,以使Nuget Project自动下载到其Visual Studio Project中?
I am learning how to use Visual Studio and publish/consume NuGet packages. After following these tutorials:
https://learn.microsoft.com/en-us/nuget/consume-packages/overview-and-workflow
I can create a simple NuGet package and publish/build it fine, as well as find the resulting .csproj project file.
One task I've been assigned is creating a Visual Studios Solution File that will automatically download a NuGet package, but I haven't seen this talked about in the NuGet documentation yet.
How can I to create a Solution File ( or maybe a project file?) for Visual Studio 2019, such that any user can consume (run?) this file with their project, to have NuGet project automatically downloaded to their Visual Studio project?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
OP:
...和OP:
所以我假设您已经发布了Nuget软件包,并通过 Manage Manage Nuget Packages在项目中引用了它对于解决方案... 至少一次,并提交结果来为您的团队中的其他人提供控制。但是问题在于,您将某种形式的自动工作流程 ,因此,当您的团队成员打开解决方案时,即使包裹在您的上,这些软件包也会自动恢复私人Nuget Server 无论您身在何处,您的团队成员环境当前未配置。这不是问题。
因此,可以做到两种方法:
1.0选择
1.1通过Visual Studio#1中的软件包管理器设置手动配置Nuget
,可以说是通过VS的用户界面完成的最简单的。不幸的是,这确实要求团队成员手动应用这些设置,这首先是您想要避免的。此外,本质上是用户cope so 将影响您在Visual Studio中打开的任何解决方案,如果多个解决方案正在使用自定义配置进行战斗,可能会导致可能的问题:
也要警告,如果像我一样,您正在工作,并将您的雇主的Nuget服务器添加到了上面,请不要惊讶构建突然停止工作,特别是Nuget Restore。我经常发现自己必须与雇主帐户进行重新认证或暂时禁用自定义Nuget源。
1.2通过nuget.config文件配置nuget。在此选项中,源控件中存在的文件
您可以通过 nuget.config 文件配置Nuget,可以将其添加到 source Control 。为什么这很重要?好吧,当您的团队通过git抓住最新的代码说话时,他们还会在回购的root文件夹中找到一个新品牌的new nuget.config 为此,将检测到,导致Nuget 的自动解决方案特定配置,该配置将 将您的自定义Nuget软件包添加到RESTORE操作中时,您可以构建解决方案。耶!。
您可以完全自由地根据范围进行自定义应用:
MSDN可以在 nuget.config 文件上说:
...和:
这是一个示例 nuget.config 。请注意,在列出标准Nuget源之前,我首先列出了我的自定义Nuget软件包源(尽管不是完全必要)。配置文件不必与Visual Studio解决方案( .sln )文件中的同一文件夹中存在,但也许是在repo root(请参阅下文),因此,当构建解决方案时,优先考虑偏好它可以在任何其他设置(包括VS的用户界面中的内容)上:
Microsoft建议您放置 nuget.config 文件(我的强调):
请务必查看MSDN上相当详细的示例配置文件。 3
1 “ nuget.config参考” ,msdn
2 “ common nuget配置” ,msdn
3 “示例配置文件”
OP:
...and OP:
So I am assuming you have already published the NuGet package, referenced it in your projects via Manage NuGet Packages for solution... at least once and committed the results to source control for others in your team to use. But the problem is that you would some form of automatic workflow so that when your team members open the solution, the packages are automatically restored even though they are on your private NuGet server wherever that may be, something your team members environment is not currently configured for. This is not a problem.
So there's a two ways this can be done:
1.0 Choices
1.1 Manually configure NuGet via Package Manager settings in Visual Studio
#1, is arguably the easiest as is done via VS's user interface. Unfortunately it does require team members to manually apply these settings which is something you wanted to avoid in the first place. Additionally is is essentially user-scope so will affect any solution you open in Visual Studio leading to possible problems if multiple solutions are fighting over custom configuration:
Also be warned, if like me you are working-from-home and have added your employer's NuGet server to the above, don't be surprised that the build suddenly stops working, specifically NuGet restore. I often find myself having to re-authenticate with my employer account or temporally disabling the custom NuGet source.
1.2 Configure NuGet via NuGet.config files present in source control
In this option you configure NuGet via nuget.config files, something that can be added to source control. Why is that important? Well when your team grabs the latest code say via Git, they'll also find a brand spanking new nuget.config in the repo's root folder that Visual Studio (and CI servers for that matter) will detect, leading to an automatic solution-specific configuration of NuGet that will add your custom NuGet packages to the restore operation when you go to build your solution. Yay!.
You have complete freedom over where such customisation are applied depending upon scope:
MSDN has this to say on nuget.config files:
...and:
Here's an example nuget.config. Note how I list my custom NuGet package source first (though not entirely necessary) before listing the standard NuGet source. The config file does not have to exist in the same folder as the Visual Studio solution (.sln) file but perhaps in the repo root (see below) so when the solution is built, preference is given to it over any other settings (including what is in VS's user interface):
Microsoft recommends that you place the nuget.config file (my emphasis):
Be sure to check out the rather detailed Example config file on MSDN.3
1 "nuget.config reference", MSDN
2 "Common NuGet configurations", MSDN
3 "Example config file"