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:
Project.Common.Presentations
project using the .csproj
file.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.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.
The basic idea of using NuGet for something like this is to share the relatively static (seldom changing) artifacts among all the projects in your solution. I personally used NuGet to also include a common master page - all my files went in the NuGet Content folder.
All my common functionality went in library projects, which obviated the need for build scripts of any kind.
Ref: Multiple web applications projects within a visual studio solution
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With