1

I have a nuget package containing some static files

<?xml version="1.0" encoding="utf-8" ?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
   ....
   ....
  </metadata>
  <files>
    <file src="static\css\index.css" target="content\static\css\index.css"/>
    <file src="static\js\index.js" target="content\static\js\index.js"/>
  </files>
</package>

If I install this package in a Visual Studio project, the files are copied to the project correctly. But when I manually delete these files from the project and try to restore the package (via "restore nuget packages" option of the Solution), the files are not copied again.

The reason is that the package is already installed

Any idea how to force the files being copied at restore?

2 Answers2

0

Looks like my idea of the restore is not how restore works

NuGet package files not being copied to project content during build

https://jeffhandley.com/2013-12-10/nuget-package-restore-misconceptions

  • Hi friend, thanks for your sharing and please mark your reply as answer and that will help other community members to search this useful information more easily, it just a reminder :) – LoLance Dec 31 '19 at 06:31
0

Any idea how to force the files being copied at restore?

Just as what described in your answer, restore option doesn't support restoring.

But if you want to force the missing files to be restored during design-time or build-time. You can consider including msbuild props and targets in nuget package.

Create a PackageID.targets file(do the restore or copy job) and place it in build folder. Then any project that consume that package will import that xx.targets file. And since the xx.targets file can involve many build-in tasks like copy task, move task...

You may get the files be restored during build by something similar to this:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="RestoreFiles" BeforeTargets="build" Condition="!Exists('static\css\index.css') Or !Exists('static\css\index.css')">
    <Copy SourceFiles="xxx" DestinationFolder="xxx"/>
  </Target>
</Project>

Also, I once met an AppDynamics.Agent.Windows in one issue that can restore the missing files even during design-time, you can get some hint from this package.(Download its xxnupkg and rename it to xx.zip=>unzip it)

So restore option can't restore the files back, if you strongly want that, consider using custom xx.targets file.

LoLance
  • 25,666
  • 1
  • 39
  • 73