简体   繁体   中英

Using nuget to update project files outside of Package Manager Console

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

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

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

UPDATE:

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

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.

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");

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

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.

Automating Visual Studio as you describe is certainly a possibility.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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