有没有一种方法可以“安装” nuget包与Visual Studio一样,但在部署服务器上 [英] Is there a way to "install" nuget package like the way Visual Studio does, but on a deployment server

查看:267
本文介绍了有没有一种方法可以“安装” nuget包与Visual Studio一样,但在部署服务器上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:



我对打包和发布nuget相当陌生。长话短说,我有一个C#项目(我们称它为MYAPI项目),该项目依赖于其他一些nuget程序包。 MYAPI的某些使用者希望将其作为一个nuget包引用,并自行处理其产品的部署,而另一些使用者希望将MYAPI dll安装在特定的文件夹中,以便在运行时从中拾取它。



因此,我将MYAPI打包为nuget,并将其发布到内部nuget服务器上。



问题:



如何将nuget软件包安装到以下服务器中具有所有必需依赖项的方式。我希望它看起来像 bin\debug 文件夹的样子,即基于目标框架,从所有依赖项nuget包(包括主nuget包)中复制相关文件(在这种情况下为MYAPI)



我知道我可以通过将MYAPI打包为zip文件或除nuget包之外的msi来实现。但我不希望MYAPI使用多种类型的软件包,而是希望仅使用nuget软件包。我也理解我可以在nuspec的< files> 部分中引用所有依赖项,但是我认为这是一个穷人的方式。



有没有一种方法可以像Visual Studio那样进行,即下载主要的nuget包及其所有依赖项,将其提取,然后从所有提取的文件中复制相关(基于框架版本)的文件nuget程序包放入 bin\debug 文件夹中。如果不能立即使用,有人可以指出VS用来将文件复制到bin\debug文件夹中的智能,以便我可以在安装脚本中复制它。



编辑:



这是一个常规的.NET Framework项目,我说的是在生产环境中进行安装服务器将无法使用MSBuild,VS等开发工具。我仍然可以使用nuget.exe命令,因为它是一个可执行文件。

解决方案


一种像Visual Studio
一样安装 nuget程序包的方法,但是在部署服务器上


我想你对这个问题有些误解,恐怕 nuget 无法实现您想要的。



实际上,它是MSBuild将相关的nuget软件包的内容复制到bin\Debug中。



实际上 MSBuild MSBuild.exe )是具有vs开发环境的可执行文件。



Nuget 只是负责将软件包下载到本地,然后将其与您的项目相关联。实际的内容复制操作纯粹是 MSBuild 的工作。



VS IDE 中, MSBuild 负责此操作。单击生成时(实际上它称为 MSBuild.exe ),nuget包的依赖项DLL将被复制到您的输出文件夹中。



要证明这一点,您可以创建一个新的空项目,然后安装此nuget软件包,然后检查文件是否在bin\Debug下。之后,请执行 Build 来检查文件是否存在。



解决方案



由于 VS2017 MSBuild 可以单独安装,而无需 VS IDE



您可以安装



由于可以与VS分开安装并且重量轻,因此许多开发人员现在都使用它在生产服务器上构建项目。



当您使用 nuget.exe 在项目中安装此类nuget程序包时,请使用Build工具执行此类命令 msbuild xxx\xxx\xxx.csproj -t:build 来构建项目。之后,您将在 bin\Debug 文件夹中看到它们。



更新1 >



实际上,nuget负责确定要复制的相应依赖项。但是nuget将这些信息传递到 MSBuild 中。 Nuget只是确定相应的信息,就像制定计划一样,具体操作由 MSBuild 执行,包括引用,还原,复制等。因此,您应该运行 MSBuild 来获取所需的信息。



此外,如果您仍然获得所需的内容,则跳过 MSBuild 直接获取文件,可以向团队建议功能。(点击建议功能)。


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. 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.

So I have packaged MYAPI as a nuget and published it onto an internal nuget server.

Issue:

How do I install my nuget package onto the servers in a way that it will have all the required dependencies. I want it to look like how the bin\debug folder looks like i.e. based on the target framework, copy the relevant files from all the dependency nuget packages including the main nuget package (MYAPI in this case)

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.

Is there a way to do it just like Visual Studio does it i.e. 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. 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.

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. I can still have the nuget.exe command as it is a single executable.

解决方案

Is there a way to "install" nuget package like the way Visual Studio does, but on a deployment server

I think you have some misunderstanding about this issue and I am afraid what you want can not be implemented by nuget.

Actually, it is MSBuild job to copy related nuget package's content into bin\Debug.

In fact, MSBuild(MSBuild.exe) is an executable with a vs development environment.

Nuget is just responsible for downloading the package to your local and then associating it with your project. The actual content copy operation is purely a job of MSBuild.

In VS IDE, MSBuild is responsible for this operation. When you click build (actually it calls MSBuild.exe), the dependency DLLs of nuget package will be copied to your output folder.

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. After that, please execute Build to check whether the files exists.

Solution

Since VS2017, MSBuild can be installed separately without VS IDE.

You can install Build Tool for Visual Studio 2019.

Under All Downloads--> Tools for Visual Studio 2019--> Build Tool for 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.

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. After that, you will see them in bin\Debug folder.

Update 1

Actually, nuget does the job which decides which corresponding dependencies to copy. But nuget passes these info into 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. So you should run MSBuild to get what you want so far.

In addition, if you still get what you want and skip MSBuild to get the file directly, you could suggest a feature to the Team.(click Suggest a Feature).

这篇关于有没有一种方法可以“安装” nuget包与Visual Studio一样,但在部署服务器上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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