Content files with 'copy to output' attribute

Apr 4, 2011 at 1:58 PM


I'm creating NuGet package and I have some files that I want to include in the target project as build action: 'None' and Copy To Output Directory: 'Copy if newer'.

Currently I do that my changing the properties of items added as a content, but I'm looking for better way of doing it.

Preferably I'd have a redist folder as a part of my NuGet pacakage and I'd include all files inside that folder as part of the target project with necessary attributes - I know how to do it manually (as a part of install.ps1) but I was hoping there'd be a better way.


Please let me know if you have any ideas or suggestions.



Apr 4, 2011 at 7:52 PM

We have a bug tracking a similar issue:

Currently, our plan is to add a PowerShell helper library that allows you to mark these things in Install.ps1. The reason we're going with this route is we don't want to bake in Visual Studio specifics into the .nuspec file. A package might be installed via a Command Line or via Web Matrix (ASP.NET Web Pages) and such concepts wouldn't apply. We want .nuspec to be universal.

But it got me thinking, there are some very common scenarios for VS that would be nice to support in a declarative way.

One thing we could do is consider having a separate .vsnuspec specifically for VS settings that would be otherwise ignored by other systems, much in the way "tools" is ignored by non-VS environments.

So if you include .vsnuspec, you could define what the Build Action is for each file if you so choose using a syntax similar to our <files> element. Thoughts?

Apr 4, 2011 at 7:55 PM

Another option is adding declarative attributes directly to the <files> element, but putting them in a different XML namespace. That way, non-VS client can easily ignore them.

Apr 5, 2011 at 11:05 AM

I like the idea of specifying attributes on files element that would be specific to Visual Studio environment.

In my case I want my files to behave like other 'content' files - I just want them to have different attributes.

Aug 23, 2011 at 5:27 PM

In the above exchange are we saying that using the following tools\install.ps1 script settings, to configure the BuildAction and CopyToOutputDirectory properties of a azure deployment related startup.cmd script that nuget package adds to web project, won't work if the packge is installed using package manager console "Install-Package <package name>" approach OR that it will break for installation of the package in environments where user is not using visual studio?

$projectItems = $project.ProjectItems
$startupCmd = $projectItems.Item("Startup.cmd")
$startupCmd.Properties.Item("BuildAction").Value = 0 # BuildAction = None
$startupCmd.Properties.Item("CopyToOutputDirectory").Value = 1 # CopyToOutputDirectory = Copy always

Either way what you are proposing in terms of a declarative way for controlling the property settings of Content that gets added to project by package would be goodness.

Sep 1, 2011 at 7:00 AM

Since getting on board with LINQ and a number of other low level things I've become a big fan of declaritive programming. So, one possibility is to have a special XML attribute (property, etc.) that is marked with an "visual studio" or "extensibility" or similar namespace that triggers a plug-in into action. The plug in can then execute the lines similar to above. You then have to keep watch over the eco system and when a set of plug-ins occur cross-platform (senario, etc.) you might fold them into the nuget core. :-)