Reputation: 23
My project is currently referencing some pre-release packages that represent nightly builds. I would like to ensure that I am always building against the latest release. I added a pre-build event to my project:
.nuget\nuget.exe update -safe -noninteractive -prerelease -source "My-Package-Repo/nuget" $(SolutionPath)
This generates the following output during build:
Scanning for projects...
Found 1 projects with a packages.config file. (MyProject)
Looking for installed packages in '..\..\packages'.
Updating 'MyProject'...
EXEC : warning : Access to the path 'C:\workspace\mainline\MyProject\packages.config' is denied.
The problem is that the packages.config file is still locked by source control and therefore NuGet cannot update the package version. Interestingly, if I run update-package
from the Package Manager Console, it automatically checks out the packages.config file and updates all packages for the solution.
Is there a way to have NuGet automatically check out the packages.config file when using the command line interface? Alternatively, is it possible to run the update-package command within the PM console as a pre-build event (since it already has the behavior I need)?
Upvotes: 1
Views: 1391
Reputation: 23434
You are using a Server Workspace (a workspace configured for Server mode). You should change to a Local Workspace.
In a local workspace files are not marked as read only and can be edited outside of Visual Studio.
Latest Nuget - if you edit the package reference in the Nuget project file you can just remove the version number. Nuget will then always load the latest version on build.
editing package.config - you should exclude the /packages/ folder from source control. In the latest versions of Nuget Package Manager this is not necessary.
Upvotes: 0
Reputation: 2204
I have been dealing with this recently myself. Unfortunately, nuget.exe update won't check out the files by itself and the package manager console only runs within Visual Studio (it apparently hooks into the Visual Studio environment to do things like enumerate projects).
If you are willing to use powershell, I would suggest the following:
1. Make a Powershell script to handle parsing the project files out of your solution
$sln = $args[0]
$projects = ((ss '= (\S+.csproj)' $sln -All) `
| % {$_.Matches.Groups[1].Value -replace "\\\\","\"})
$configFiles = $projects -replace '(?<=\\)[^\\]+?\.csproj', 'packages.config'
'tf checkout ' + ($projects -join ' ') | iex
'tf checkout ' + ($configFiles -join ' ') | iex
('.nuget\nuget.exe update -safe -noninteractive -prerelease -source "My-Package-Repo/nuget"' `
+ $sln) | iex
2. Put that powershell script in the same folder as your solution
3. Call that powershell script from your pre-build event
powershell -file $(SolutionDir)nuget-update.ps1 "$(SolutionPath)"
To undo any changes to project and config files that weren't changed, run tfpt uu noget
after the above.
Upvotes: 2