Search code examples
visual-studio-2010embedded-resource

VS2010 not embedding files into assembly


For some reason in VS2010 I can't embed any file into an assembly. These files have their Build Action property set to Embedded Resource as they should, but when the assembly is executed it founds no resources. For example, the following test code:

string[] list = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();
string msg = (list.Length > 0) ? "Full" : "Empty";
MessageBox.Show(msg);

always shows "Empty" because GetManifestResourceNames() always returns an empty list.

This issue affects a project using nettiers in which is not convenient for that particular case to include the stored procedures into the DB, so they must be taken from the Procedures.xml file, which BTW is automatically set with Build Action= Embedded Resource after the classes generation, and then of course when a function tries to get any SQL script from it, the program fails.

I also created a couple of test projects where I tried to embed an xml and a gif, always with no success.

Update: The problem seems to be only for C#. I reproduced the test project in VB.Net and there the file does get embedded. I've noticed that in the output window, in the C# case, the compiler command line doesn't include the /resource option (which should be there followed with the name of the file to embed) whereas for the VB case it does appear.

Are there any global settings or configuration files anywhere for C# I should check? (The build options for the project have nothing strange there)

Does anyone have an idea of what may be happening and how to fix this?


Solution

  • Finally, I found the cause:

    There was a wrong line inside the Microsoft.CSharp.targets file (located inside c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319). There was a tag written as:

    <EmbeddedResourceF Include="@(_Temporary)" />

    instead of

    <EmbeddedResource Include="@(_Temporary)" />

    Writing it right restored the ability to embed files

    How that F appeared and why that file got altered in first place, I dont know... Despite being a .NET programmer for several years I just became aware today of the ".targets" files after searching the web about this issue, as never have had the need to look about the MSBuild stuff.