I have come across an issue whereby the resource names given to embedded resources in an assembly are different when built by NCrunch as apposed to Visual Studio. Visual Studio includes the root namespace of the assembly as well as any containing folders; whereas NCrunch only has the root namespace. Seen running NCrunch 2.22.0.1 in Visual Studio 2015. This is only the case when the resources are included as part of a Shared Project.
Steps to reproduce: -
1. Create a new solution
2. Create a shared project
3. Create a new folder (e.g. "MyResources")
4. Create a new text file (e.g. "Text File") and set the build action as "Embedded Resource"
5. Create a new Class Library and add the latest NUnit package
6. Add a reference to the shared project
7. Add the following test class: -
using System;
using System.Reflection;
using NUnit.Framework;
namespace TestClasses
{
[TestFixture]
public sealed class ResourceTest
{
[Test]
public void TestResources()
{
string[] resourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
foreach (string resourceName in resourceNames)
{
Console.WriteLine(resourceName);
}
}
}
}
8. Ensure NCrunch is running
The output from the test will look something like this: -
TestClasses.Text File.txt
If you look at the assembly manifest using a tool such as ILDASM you'll see something like this: -
.mresource public 'TestClasses.MyResources.Text File.txt'
Note the extra "MyResources" portion of the path.
If a file is added as a linked file, the problem does not occur and any folder hierarchy is correctly present in the resulting resource name.
Nick Hall
Build/Test Issues
Embedded resources in a shared project lose their folder hierarchy when built by NCrunch
Started by nshallred on 4,803 views
Remco NCrunch Developer
#8713
06 May 2016 02:56 UTC
Hi Nick,
Thanks for sharing this issue, it was a good find.
Apparently MS recently introduced changes to the build targets used to prepare a project prior to its build. These changes included the introduction of a target responsible for assigning a default value to the 'Link' metadata item on EmbeddedResource project items. The change itself isn't compatible with an area of the build NCrunch overrides, so the target isn't being executed. This means that the 'Link' metadata isn't being set automatically for embedded resources inside NCrunch builds, so the namespace isn't being correctly calculated when the resources are being attached to the built assembly.
As you've already discovered, assigning a 'Link' tag to the affected embedded resources will allow you to work around this problem. This is the cleanest way I've found to allow you to continue to function with this issue.
A fix for this will be available in the next version of NCrunch.
Thanks for sharing this issue, it was a good find.
Apparently MS recently introduced changes to the build targets used to prepare a project prior to its build. These changes included the introduction of a target responsible for assigning a default value to the 'Link' metadata item on EmbeddedResource project items. The change itself isn't compatible with an area of the build NCrunch overrides, so the target isn't being executed. This means that the 'Link' metadata isn't being set automatically for embedded resources inside NCrunch builds, so the namespace isn't being correctly calculated when the resources are being attached to the built assembly.
As you've already discovered, assigning a 'Link' tag to the affected embedded resources will allow you to work around this problem. This is the cleanest way I've found to allow you to continue to function with this issue.
A fix for this will be available in the next version of NCrunch.
Post a reply
Log in to reply.