NuGet package without adding files to Visual Studio project
I am just getting started with NuGet and trying to get my head around it. I may be trying to use NuGet for someting it isn't in开发者_开发知识库tended for, but I was hoping someone might give me some hints.
My issue: I am trying to create a package with different files. The files is of different type (images, text files, etc.). I want the package to work, so that the files get added to my application root, but isn't included in my visual studio project. I have tried it, but the files is always added to the project. Is there a way around this?
Thanks
There is no direct support for this today. Anything that you put in the content folder gets added to your project when the package is installed.
However, you should be able to achieve this result using an install.ps1 script, e.g.:
- Put all the files you want to end up in your web root in some folder in the package
- Use PowerShell in install.ps1 to copy everything in that folder into your web root, which is probably just a one-liner.
You can put your files in another folder (not content) in the nuget packet and add a .targets file to your nuget packet copy the files at build time.
MyProject.nuget file:
...
<files>
<file src="bin\$configuration$\$id$.pdb" target="lib\net45"/>
<file src="C:\MyResourceFolder\**" target="resources"/>
<file src="MyProject.targets" target="build"/>
</files>
</package>
MyProject.targets file:
<?xml version="1.0"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)\..\resources\**">
<Link>\Recources\%(RecursiveDir)\%(Filename)%(Extension)</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
When you build your final Application the files will be copy'ed to the build target folder.
精彩评论