Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Embedded resources in a shared project lose their folder hierarchy when built by NCrunch
nshallred
#1 Posted : Thursday, May 5, 2016 10:11:51 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 5/5/2016(UTC)
Posts: 4
Location: United Kingdom

Thanks: 1 times
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

Remco
#2 Posted : Friday, May 6, 2016 2:56:09 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 6,993

Thanks: 932 times
Was thanked: 1258 time(s) in 1171 post(s)
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.
1 user thanked Remco for this useful post.
nshallred on 5/6/2016(UTC)
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.039 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download