简体   繁体   English

MSBuild在构建时将nuget包应用于项目

[英]MSBuild to apply a nuget package to a project at build time

I have a cmake project that builds fine on Linux and that I want to build also on Windows. 我有一个cmake项目,该项目可以在Linux上很好地构建,并且我也想在Windows上构建。 The code is portable and is made of C++ so... it should build. 该代码是可移植的,由C ++制成,因此...应该构建。 The only thing is that, on Windows, I need to use nuget to restore some packages, cpprestsdk is one of them. 唯一的问题是,在Windows上,我需要使用nuget还原某些软件包,cpprestsdk是其中之一。 Now when I run 现在当我跑步

cmake . 

CMake will generate solution files and projects files that I don't want to include in my VCS at all. CMake将生成我完全不希望包含在VCS中的解决方案文件和项目文件。 The thing I want MSBuild to do is to apply the packages contained in my packages.config to all the project files found in the project directory. 我希望MSBuild要做的是将我的packages.config中包含的包应用于项目目录中找到的所有项目文件。 Anyone knows how? 有人知道吗?

The thing I want MSBuild to do is to apply the packages contained in my packages.config to all the project files found in the project directory. 我希望MSBuild要做的是将我的packages.config中包含的包应用于项目目录中找到的所有项目文件。 Anyone knows how? 有人知道吗?

I am afraid you can not do such things. 恐怕你不能做这样的事情。 That because whether you are using MSBuild or NuGet to do this thing, you have to use to the nuget.exe to do it. 那是因为无论您是使用MSBuild还是NuGet来执行此操作,都必须使用nuget.exe来执行。 However, install nuget packages to the project file relies on VS capabilities not nuget.exe and nuget team not plan to bring it to the exe. 但是,将nuget软件包安装到项目文件不是依靠nuget.exe ,而是依靠VS功能,并且nuget团队不打算将其引入exe。

The NuGet Command Line does not actually install any packages. NuGet命令行实际上并未安装任何软件包。 The install command is actually doing a restore operation. install命令实际上正在执行还原操作。

This means that nuget.exe install will only download and extract the package into the output location. 这意味着nuget.exe安装将仅下载软件包并将其解压缩到输出位置。 It will not modify the project file. 它不会修改项目文件。 Although, the package manager console seem to offer " Install-Package " for doing this, but you have to open each project files with Visual Studio and execute Install-Package in the package manager console for each project files, which is not what you want. 尽管,软件包管理器控制台似乎为此提供了“ Install-Package ”,但是您必须使用Visual Studio打开每个项目文件,并在软件包管理器控制台中为每个项目文件执行Install-Package ,这不是您想要的。 So you could not enable this script outside of visual studio. 因此,您无法在Visual Studio之外启用此脚本。

So we could not use MSBuild to apply the packages contained in the packages.config to all the project files found in the project directory. 因此,我们无法使用MSBuild将packages.config中包含的软件包应用于项目目录中找到的所有项目文件。

You can refer to this thread and this thread for details. 您可以参考此线程该线程以获取详细信息。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM