Earlier this week I posted a question about how to effectively share files amongst multiple web applications within a solution. NuGet was offered as a solution and after some time I was able to implement a solution, but I have one issue that is currently blocking me from finishing it.
At this point I have two web application projects:
Project.Common.Presentations
Project.Website.Presentations
Each time the Project.Common.Presentations
project is build, a new NuGet package with a higher version is created. This package is used in my main web project Project.Website.Presentations
. Initially I add the project.common.presentations NuGet package to this project through the GUI. Right after that I setup a pre-build eveny where I do a NuGet update from the command line to pull in the latest version of the Project.Common.Presentations
package.
But somehow using NuGet update in the command line adds a reference to my project using a location that’s not actually on disk, leading to this issue:
Could not resolve this reference. Could not locate the assembly "Project.Common.Presentations". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
This is how I set up the structure:
- I generated a NuSpec file for my
Project.Common.Presentations
project using the.csproj
file. - As a post-build event in my
Project.Common.Presentations
, I use:$(ProjectDir)nuget.exe pack -sym $(ProjectPath)
. This builds a new NuGet package every time the project is build. Before this build-event is executed I use a script to delete the old NuGet packages. - As a pre-build event in my
Project.Website.Presentations
I use:$(ProjectDir)NuGet.exe update $(ProjectDir)packages.config
The first rebuild all is run, my .csproj
file is updated with a dll reference to my package, all is fine and good. The second time I run rebuild all, the .csproj
file is updated again, but it references a different folder with a newer version of the package but the folder somehow is not on the drive. When I use the GUI "Manage NuGet packages" to update the NuGet package this problem does not occur, everything works fine.
Removing the pre-build event, and updating the package manually works fine. But having to do something manually each time you build is not something I enjoy. Using the Package Manager Console to uninstall and install the package also works fine. Is there a way to incorporate Package Manager Console action into a pre-build event? Thanks in advance for the information.