3

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 intended 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

2 Answers 2

6

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.
Sign up to request clarification or add additional context in comments.

Comments

3

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.