To pack some resource files into a nuget package, what one would normally do, is the following.
Put all the resource files into the content\
directory of a nuget package. This would be specified by the following line in a .nuspec
file:
<files>
<file src="Project\bin\Release\script.js" target="content\js\script.js" />
<files>
Now, when this nuget package gets installed into AnotherProject
, the following file structure emerges:
Solution.sln
packages\Project.1.0.0\content\js\script.js // the original resource file
AnotherProject\js\script.js // a physical copy
AnotherProject\AnotherProject.csproj // <Content /> tag (see below)
During package installation, AnotherProject.csproj
was injected with tag:
<Content Include="js\script.js" />
and this is for the physical copy of the original resource (which is under packages\
directory).
My aim is not to have the physical copy of a resource file in the AnotherProject
directory but rather a "link" to the original resource under packages\
directory. In the csproj, this should look like this:
<Content Include="packages\Project.1.0.0\content\js\script.js">
<Link>js\script.js</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
Now, one "do it the hard way" workaround I can think of is:
content\
so they do not get added automatically,Install.ps1
script that would hack the csproj file structure and add the necessary XML piece manually,This, however, has the following drawbacks:
Install.ps1
,Since NuGet currently does not support this out of the box your options are either to use PowerShell or to use a custom MSBuild target.
PowerShell
You should be able to avoid the project reload prompt if you use the Visual Studio object model (EnvDTE). I would take a look at Project.ProjectItems.AddFromFile(...) to see if that works for you.
MSBuild target
Typically the custom .props and .targets are used to customise the build process. However they are just MSBuild project files so you could add items for your resources into these project files.
Note that .props are imported at the start of the project file when a NuGet package is installed, whilst .targets are imported at the end of the project.
Customising NuGet
Another option, which would take more work, would be to modify NuGet to support what you want to do.
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