Is it possible to rename a file during copy with Nuspec files node

914 views Asked by At

I am currently working on changing our codebase to use Nuget. As part of the process the copying of ressources to the output directory should be moved from postbuild events in the projects to the files tag in the .nuspec file.

For the particular project the ressource was called Resources.resx and is renamed to something more specific during the copy (yes I know great programming - not mine and not my place to change it).

Is it possible to change the filename using the file node in nuspec or do I need to keep a postbuild in this case?

My attemp of renaming it with the target property fails:

< file src="foo/bar.resx" target="foo/foobar.resx"/>

creates the following output: "foo/foobar.resx/bar.rex"

I found a familiar problem on github but it was rejected due to being posted on a dead branch and not trying to rename a file but change its type.

https://github.com/NuGet/Home/issues/2019

Thanks for the help

2

There are 2 answers

0
techvice On

This functionality is not built into NuGet. The only conceivable way to do this would be to implement a powershell script (install.ps1) that would handle the rename of both the file and the csproj.

0
Albert On

Late to the party, but this looks like it could work:

From: https://learn.microsoft.com/en-us/nuget/reference/nuspec

Renaming a content file in the package

Source file:
ie\css\style.css

.nuspec entry:
<file src="ie\css\style.css" target="Content\css\ie.css" />

Packaged result:
content\css\ie.css

Edit:

I found this post (https://stackoverflow.com/a/45601252/182888) where it says:

Note: The File extension in src and target must match or the specified target will be treated like a directory.

So keep that in mind or it might trip you up.