使用 nuget 在包管理器控制台之外更新项目文件 [英] Using nuget to update project files outside of Package Manager Console

查看:56
本文介绍了使用 nuget 在包管理器控制台之外更新项目文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Nuget.exe 仅支持在文件系统/配置级别管理包.powershell 命令命令更新 .proj 文件的魔法.

Nuget.exe only supports managing packages at a file system/configuration level. The powershell commands command the magic that update the .proj files.

话虽如此,我需要能够在 Visual Studio(自动)之外使用最新版本的 NuGet 包更新 csproj 文件.

With that said, i need the ability to update a csproj file with the latest version of a NuGet package outside of visual studio (automated).

基本上,我如何在我自己的外部 powershell 脚本中使用 Install-Package(或任何其他方法)?

Basically, how do I use Install-Package (or any of the other methods) inside of an external powershell script of my own?

更新:

出于以下原因,我希望能够在 VS 之外添加项目引用.

I would like to ability to add project references outside of VS for the following reason.

我的公司有很多共享库,在某些情况下它们相互依赖.我正在使用 TFS Nugetter 从 TFS 构建和发布 nuget 包.我想确保开发人员不能对构建(包)进行排队,除非该项目可以在所有较新版本上构建和运行.这确保了所有较新版本的库都能与其依赖项的所有较新版本一起使用.如果构建失败,那么您需要在 VS 中更新您的 nuget 引用并修复编译器错误/单元测试.

My company has a lot of shared libraries that depend on each other in some cases. I am using TFS Nugetter to build and publish nuget packages from TFS. I want to ensure that the developers can't queue a build (package) unless the project can build and run on all the newer versions. This ensures that all the newer versions of the libraries work with all the newer versions of its dependencies. If the build fails, then you need to update your nuget reference in VS and fix the compiler errors/unit tests.

我一直在查看 NuGet 源代码,我想我找到了一种简单的方法来重用 NuGet 源代码来修改 VS 之外的项目文件(有点).

I have been looking at the NuGet source and I think I found an easy way to reuse NuGet source to modify proj files outside of VS (kinda).

System.Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0", true);
var dte = (DTE)System.Activator.CreateInstance(t, true); 
dte.Solution.Open( 
    @"C:\Users\paul.knopf\Documents\Visual Studio 2010\Projects\SLNMemory\SLNMemory.sln");

基本上,打开 Visual Studio 的内存版本,运行 nuget 命令,然后保存.

Basically, open an in-memory version of visual studio, run the nuget commands, then save.

在构建步骤中,在 GetWorkspace 之后,我想在内存中运行此 vs 将所有 nuget 引用更新到最新版本.

In a build step, after GetWorkspace, I would like to run this in-memory vs to update all nuget references to the latest version.

你怎么看?这肯定会很慢,但我们会使用相同的代码库并拥有我们需要的所有功能.

What do you think? It would definitely be slow, but we would be on the same code base and have all the functionality we need.

推荐答案

如您所描述的那样自动化 Visual Studio 肯定是可能的.

Automating Visual Studio as you describe is certainly a possibility.

我查看的另一种方法是使用 SharpDevelop 来安装Visual Studio 之外的 NuGet 包.NuGet PowerShell cmdlet 已修改为接受解决方案,您可以从命令行自动安装,包括在 NuGet 包中使用 PowerShell 脚本.代码尚未更新,因此它针对旧版本的 NuGet,但可以更新.同样,这类似于您的解决方案和相当重量级的解决方案.

Another way I looked at was using SharpDevelop to install NuGet packages outside of Visual Studio. The NuGet PowerShell cmdlets were modified to accept a solution and you could automate installation, including the use of PowerShell scripts in a NuGet package, from the command line. The code has not been updated so it targets an old version of NuGet but could be updated. Again this is similar to your solution and fairly heavyweight solution.

这篇关于使用 nuget 在包管理器控制台之外更新项目文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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