c# - How to tell nuget to add package resource files as links, and not copy them into project directory -
intro (how pack resources nuget package)
to pack resource files nuget package, 1 do, following.
put resource files content\
directory of nuget package. specified following line in .nuspec
file:
<files> <file src="project\bin\release\script.js" target="content\js\script.js" /> <files>
now, when nuget package gets installed anotherproject
, following file structure emerges:
solution.sln packages\project.1.0.0\content\js\script.js // original resource file anotherproject\js\script.js // physical copy anotherproject\anotherproject.csproj // <content /> tag (see below)
during package installation, anotherproject.csproj
injected tag:
<content include="js\script.js" />
and physical copy of original resource (which under packages\
directory).
the actual problem (how pack resources nuget package link)
my aim not have physical copy of resource file in anotherproject
directory rather "link" original resource under packages\
directory. in csproj, should this:
<content include="packages\project.1.0.0\content\js\script.js"> <link>js\script.js</link> <copytooutputdirectory>preservenewest</copytooutputdirectory> </content>
brute force solution rather avoid
now, 1 "do hard way" workaround can think of is:
- not putting resource files under
content\
not added automatically, - writing
install.ps1
script hack csproj file structure , add necessary xml piece manually,
this, however, has following drawbacks:
- all nuget packages need same script piece in
install.ps1
, - when installing packages, there nasty "project reload prompt" in visual studio.
since nuget not support out of box options either use powershell or use custom msbuild target.
powershell
- leave resources outside of content directory in nuget package (as suggested).
- add file link using powershell in install.ps1.
you should able avoid project reload prompt if use visual studio object model (envdte). take @ project.projectitems.addfromfile(...) see if works you.
msbuild target
- nuget supports adding import statement project points msbuild .props and/or .targets file. put resources tools directory of nuget package , reference them custom msbuild .props/.targets file.
typically custom .props , .targets used customise build process. msbuild project files add items resources these project files.
note .props imported @ start of project file when nuget package installed, whilst .targets imported @ end of project.
customising nuget
another option, take more work, modify nuget support want do.
Comments
Post a Comment