Support for an embedded resource

Sep 18, 2010 at 4:35 AM

What are the thoughts on how I can change the Bulid Action of a content file to a EmbeddedResource ? I could write an .  The nuspec does not support this out of the box. 

Sep 18, 2010 at 6:45 AM

That had come up a while back, but I think we didn't have a concrete scenario.  In most case, the Build Action that VS picks based on the extension does the right thing.  Can you explain what kind of package would make use if that?  We might need to put it on the radar.

Sep 18, 2010 at 12:59 PM

I have a fork called np2, inside is a portable area package.

I have a txt file called release notes that needs to be an embedded resource when it is added to the project.  So a convevtion might not work here.

Sep 18, 2010 at 4:35 PM

Ok, let's track this as something we need to look at.

It's somewhat tricky with the pure convention approach that we recently switched to.  Maybe it can be done via special extensions.  e.g. foo.txt.BuildActionEmbeddedResource.

Sep 20, 2010 at 9:26 PM

I do not like the idea of having to rename files with the additional extension.  The reason being is that as a project is built I would like to leave the resources unchanged.   For exceptions to the convention I would rather just include an install powershell script and specifiy that special handling of the file once, rather than have to remember to rename the extension, if it is manual or have the file constantly renamed if it is scripted into the build script.

Sep 20, 2010 at 9:47 PM

Using the install PS script is definitely an option, though it's pretty manual.  Looks like it can be done by setting projItem.Properties.Item("BuildAction").

Sep 20, 2010 at 9:51 PM

Yes, I have some sample code to do this.  I will work up a little POC and put it in my package.

Sep 20, 2010 at 9:57 PM

Look at PackageSources\SQLCE\Tools\install.ps1 to see how to get access to the current project.  i.e. first line should be:

    param($installPath, $toolsPath, $package, $project)


Sep 21, 2010 at 10:18 PM

Ok, I got this sample working for the Portable Area package. I implemented this using a Install.ps1 script.

param($installPath, $toolsPath, $package, $project)

$item = $project.ProjectItems | where-object {$_.Name -eq "ReleaseNotes.txt"}
$item.Properties.Item("BuildAction").Value = [int]3


If anyone has a cleaner way to implement this please let me know. I think this really shows how extensible the system is by exposing the powershell installation extension points.

Sep 21, 2010 at 10:29 PM

Looks good.  Maybe a bit simpler:

$item = $project.ProjectItems.Item("ReleaseNotes.txt")

Powershell DTE programmability indeed makes the system very flexible.

Oct 15, 2014 at 8:17 AM
I'd like to revive this thread. I am working in the context of Xamarin / Xamarin Studio on a Mac, so don't have access to either PowerShell or DTE. Our application needs to include some content as an embedded resource and that content is made available to the project via a private feed NuGet package. It would be really helpful to be able to have a way to designate certain files as "embedded resource" using .nuspec.