[英]Is there a way to "install" nuget package like the way Visual Studio does, but on a deployment server
Background:背景:
I am reasonably new to packaging and publishing nuget. Long story short, I have a C# project (Let's call it MYAPI project) which depends on a bunch of other nuget packages.我对打包和发布 nuget 相当陌生。长话短说,我有一个 C# 项目(我们称之为 MYAPI 项目),它依赖于一堆其他 nuget 包。 Some consumers of MYAPI, expect to reference it as a nuget package and deal with their products' deployment on their own, while some other consumers expect MYAPI dlls to be installed in specific folders from where they will pick it up at runtime.
MYAPI 的一些消费者希望将其引用为 nuget package 并自行处理其产品的部署,而其他一些消费者希望 MYAPI dll 安装在特定文件夹中,他们将在运行时从中获取它。
So I have packaged MYAPI as a nuget and published it onto an internal nuget server.所以我将 MYAPI 打包为 nuget 并将其发布到内部 nuget 服务器上。
Issue:问题:
How do I install my nuget package onto the servers in a way that it will have all the required dependencies.如何将我的 nuget package 安装到服务器上,使其具有所有必需的依赖项。 I want it to look like how the
bin\debug
folder looks like ie based on the target framework, copy the relevant files from all the dependency nuget packages including the main nuget package (MYAPI in this case)我希望它看起来像
bin\debug
文件夹的样子,即基于目标框架,从所有依赖项 nuget 包中复制相关文件,包括主要的 nuget package(在本例中为 MYAPI)
I know I can achieve this by packaging MYAPI as a zip file or an msi in addition to the nuget package. But I don't want multiple types of packages for MYAPI, and would prefer to stick to just nuget package. I also understand I can reference all the dependency in my <files>
section of nuspec, but I think it is a poor man's way of doing it.我知道除了 nuget package 之外,我可以通过将 MYAPI 打包为 zip 文件或 msi 来实现这一点。但是我不希望 MYAPI 有多种类型的包,并且宁愿只使用 nuget package。我也明白我可以引用 nuspec 的
<files>
部分中的所有依赖项,但我认为这是一个穷人的做法。
Is there a way to do it just like Visual Studio does it ie download main nuget package and all its dependencies, extract them and then copy the relevant (framework version based) files from all the extracted nuget packages into the bin\debug
folder.有没有办法像 Visual Studio 那样做,即下载 main nuget package 及其所有依赖项,解压缩它们,然后将所有解压缩的 nuget 包中的相关(基于框架版本)文件复制到
bin\debug
文件夹中。 If that is not available out of the box, can someone point me to the "intelligence" VS uses to copy the files into bin\debug folder, so i can replicate it in an install script.如果那不是开箱即用的,有人可以告诉我 VS 用来将文件复制到 bin\debug 文件夹的“智能”,这样我就可以在安装脚本中复制它。
EDIT:编辑:
This is a regular .NET Framework project, and I am talking of installing on say a production server where development tools like MSBuild, VS won't be available.这是一个常规的 .NET 框架项目,我说的是在生产服务器上安装,其中 MSBuild 等开发工具不可用,VS 将不可用。 I can still have the nuget.exe command as it is a single executable.
我仍然可以使用 nuget.exe 命令,因为它是一个可执行文件。
Is there a way to “install” nuget package like the way Visual Studio does, but on a deployment server
有没有办法像 Visual Studio 那样“安装”nuget package,但是在部署服务器上
I think you have some misunderstanding about this issue and I am afraid what you want can not be implemented by nuget .我想你对这个问题有些误解,恐怕nuget无法实现你想要的。
Actually, it is MSBuild job to copy related nuget package's content into bin\Debug.实际上,将nuget相关包的内容复制到bin\Debug中是MSBuild的工作。
In fact , MSBuild ( MSBuild.exe
) is an executable with a vs development environment.其实MSBuild (
MSBuild.exe
)是一个带有vs开发环境的可执行文件。
Nuget is just responsible for downloading the package to your local and then associating it with your project. Nuget只是负责将package下载到你的本地,然后关联到你的项目中。 The actual content copy operation is purely a job of MSBuild .
实际的内容复制操作纯粹是MSBuild的工作。
In VS IDE , MSBuild is responsible for this operation.在VS IDE中, MSBuild负责这个操作。 When you click build (actually it calls MSBuild.exe ), the dependency DLLs of nuget package will be copied to your output folder.
当你点击构建时(实际上它调用了 MSBuild.exe ), nuget package 的依赖DLL将被复制到你的 output 文件夹中。
To prove it , you can create a new empty project and then install this nuget package, then check whether the files are under bin\Debug.为了证明这一点,你可以新建一个空项目,然后安装这个nuget package,然后检查文件是否在bin\Debug下。 After that, please execute Build to check whether the files exists.
之后,请执行Build检查文件是否存在。
Solution解决方案
Since VS2017 , MSBuild can be installed separately without VS IDE .从VS2017开始,可以单独安装MSBuild ,不用VS IDE 。
You can install Build Tool for Visual Studio 2019 .您可以安装Build Tool for Visual Studio 2019 。
Under All Downloads --> Tools for Visual Studio 2019 --> Build Tool for Visual Studio 2019在所有下载下 --> Visual Studio 2019 工具--> Visual Studio 2019构建工具
Since it can be installed separately from VS and is lightweight, many developers now use this to build projects on production servers.由于它可以独立于VS安装且轻量级,所以现在很多开发者使用它在生产服务器上构建项目。
When you use nuget.exe
install such nuget package in your project,then use Build tool to execute such command msbuild xxx\xxx\xxx.csproj -t:build
to build project.当你使用
nuget.exe
在你的项目中安装这样的 nuget package 然后使用构建工具执行这样的命令msbuild xxx\xxx\xxx.csproj -t:build
来构建项目。 After that, you will see them in bin\Debug
folder.之后,您将在
bin\Debug
文件夹中看到它们。
Update 1更新 1
Actually , nuget does the job which decides which corresponding dependencies to copy.实际上,nuget 的作用是决定复制哪些对应的依赖项。 But nuget passes these info into MSBuild .
但是 nuget 将这些信息传递给MSBuild 。 Nuget just determines the corresponding information which is like making a plan,the specific action is performed by MSBuild , including reference, restore, copy, and so on.
Nuget只是确定相应的信息,就像制定计划一样,具体的动作由MSBuild执行,包括引用、恢复、复制等。 So you should run MSBuild to get what you want so far.
所以你应该运行MSBuild来得到你想要的。
In addition , if you still get what you want and skip MSBuild to get the file directly, you couldsuggest a feature to the Team .(click Suggest a Feature ).另外,如果你仍然得到你想要的并跳过MSBuild直接获取文件,你可以向团队建议一个功能。(点击建议一个功能)。
You can use a temporary/publish project.您可以使用临时/发布项目。 Create the project with whatever TFM you want, add a PackageReference to the package, run
do.net publish
, then delete <project_name>.*
from the publish directory.使用所需的任何 TFM 创建项目,将 PackageReference 添加到 package,运行
do.net publish
,然后从发布目录中删除<project_name>.*
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.