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

Notification

Icon
Error

NCrunch doesn't appear to copy linked content files to output directory
rjsinden
#1 Posted : Wednesday, August 14, 2013 9:13:52 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/14/2013(UTC)
Posts: 4
Location: United Kingdom

Was thanked: 1 time(s) in 1 post(s)
Hi,

I'm just trying out NCrunch for the first time, and I've hit an issue which I couldn't see mentioned anywhere else on the forums (apologies if it is).

I have a test project configured with several additional test data files which need to be copied to the test directory.
Some of those files are stored within the test project and some are shared between a couple of projects and therefore added as links. The files that are added as links are not copied to the workspace when NCrunch builds the project.

Example from .csproj file:

These files are copied:
Code:
    <Content Include="TestData\XML\UserList.xml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>


These linked files are not copied:
Code:
    <Content Include="..\Reports\SessionsByLocation.trdx">
      <Link>TestData\Reports\SessionsByLocation.trdx</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>


I have tried setting "Copy referenced assemblies to workspace", but that doesn't seem to make any difference. Is there a setting that I'm missing somewhere? I'd prefer to keep the linked files where they are rather than have multiple copies under each of my projects, if possible.

Thanks,

Richard
1 user thanked rjsinden for this useful post.
Bart1 on 6/19/2016(UTC)
Remco
#2 Posted : Wednesday, August 14, 2013 10:15:09 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Richard -

Thanks for posting!

In theory, this should just 'work', as NCrunch detects the relatively linked paths through the Content tags and should already be aware of them. There should be no setting required for this, and I'm not aware of any setting that could impact its behaviour.

I'm wondering if you could check something for me...

After the problem project has built (or failed to build), can you right click on it, then go to Advanced->Browse to workspace. This should open up the newly created workspace for this project in explorer. Browsing through the workspace, do you see the targeted files anywhere along their expected path relative to the project file? I'm wondering if NCrunch is actually aware of these files and is copying them, but perhaps some other mechanism downstream is failing.

If you can't find the files in the workspace, I may need to get a code sample from you to figure out why this is misbehaving ...


Cheers,

Remco
rjsinden
#3 Posted : Wednesday, August 14, 2013 10:26:18 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/14/2013(UTC)
Posts: 4
Location: United Kingdom

Was thanked: 1 time(s) in 1 post(s)
Hi Remco,

Cheers for getting back to me so quickly.

You're right, I went up a directory from the workspace and it appears that it is copying them to the Include location, not the Link location. So, from my example above, the file appeared at "..\Reports\SessionsByLocation.trdx", not "TestData\Reports\SessionsByLocation.trdx" as it was supposed to. It sounds like it is just ignoring the Link element. Is there anything I can do about this, or is it a bug?

Thanks,

Richard
Remco
#4 Posted : Wednesday, August 14, 2013 10:56:30 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Richard -

My (perhaps incorrect) understanding of the Link element is that it is merely cosmetic - allowing the file to be given a friendlier name inside the solution explorer in the IDE. Without the link element, the file would always appear at the root level of the project. Is it possible that you have an identical file located at the Link path in your source solution? If so, I'm fairly certain NCrunch won't identify or copy this file, as NCrunch would not consider it a dependency of the project. If you have a clone of the file sitting at the end of a Link path, it probably defeats the point of using the Link element entirely, as the cloned file could simply be referenced directly (i.e. <Content Include="TestData\Reports\SessionsByLocation.trdx" />).

Do you think this fits your scenario? I'm not 100% confident of my understanding of this element, so feel free to correct me if I have this wrong.


Cheers,

Remco
rjsinden
#5 Posted : Thursday, August 15, 2013 12:10:15 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/14/2013(UTC)
Posts: 4
Location: United Kingdom

Was thanked: 1 time(s) in 1 post(s)
Hi Remco,

You are partially right about the Link element being cosmetic. It is in most situations, except when you have "Copy to output directory" set to something other than "Do not copy". In that case, when you build, it will create a copy of the file in the output directory at the relative path specified under the Link element. It will use the Include attribute of the content element as the source path so that there does not need to be a copy of the file at the link path under the project directory.
The important thing about the Link element is that its presence means that the path in the Include attribute is not within the project's directory structure - it could even be an absolute path to some completely unrelated location (although that probably wouldn't be very good practice). I suspect that this means that NCrunch isn't doing the right thing if it is copying to the Include location rather than the Link, if Link is present.

I've been trying to find some actual documentation on how it works, and I found this, which isn't entirely helpful: http://msdn.microsoft.com/en-us/library/vstudio/bb629388.aspx. It does appear to have a copy and paste error on the Content/Link element description though, because it looks like a copy of the Visible element description. The Link elements on the other items are described properly.

I should probably add that these bits in the .csproj file were generated by Visual Studio, using Add -> Existing Item... and then click "Add as link" on the Add button drop down. I haven't edited it manually.

Thanks,

Richard
Remco
#6 Posted : Thursday, August 15, 2013 12:24:25 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Richard,

Thanks - this makes sense. I think an important distinction we need to make is around the difference between NCrunch setting up the workspace for your project, and the project itself being built. The goal of workspace construction is to be able to create a project with the exact same relative structure as the project in your source solution. From this perspective, the Link declarations aren't really relevant during workspace construction - as the files pointed to by the Link don't actually exist (or rather shouldn't exist) in the source project (at least, not in the Link location), so they shouldn't really exist in the workspace in this location.

Based on what you've described, the Link declaration itself becomes very relevant when the project is built, as MSBuild needs to use this path to make sure it copies the file to the right location during the build. So when NCrunch builds the project, it should be complying with normal build logic and copying the files to the appropriate Link locations inside the workspace - probably in the Bin\Debug directory or where ever the build is set to output files.

I appreciate this is probably a little confusing with the amount of file copying involved, but basically we're talking about: FileInSourceSolution----COPIED-BY-NCRUNCH-TO->FileInWorkspace----COPIED-BY-MSBUILD-TO->FileInProjectOutputDirectory

So if my understanding is correct, the key question is: Why are these files not being found in their expected Link location after NCrunch builds the project?

Can you share any more details around how you are searching for these files at run-time? Are these resources being used by your code under test?


Cheers,

Remco
rjsinden
#7 Posted : Thursday, August 15, 2013 12:47:17 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 8/14/2013(UTC)
Posts: 4
Location: United Kingdom

Was thanked: 1 time(s) in 1 post(s)
Hi Remco,

Aha, thanks for the explanation, it suddenly all becomes clear and I think it might've been a bit of an idiot.
The files are where they are supposed to be, I was just looking at the TestData\Reports entry in the workspace root, rather than in the bin directory underneath it.

The reason I thought I had an issue is that one of the files that should have been copied across was set as a "Resource" rather than "Content" (I'm not sure how that happened), so it wasn't getting copied. It was there in my local bin folder though (must've been copied before the file type was changed), so the tests were passing when I ran them manually. Unfortunately, it was a fairly critical file, so it was causing all my tests to fail when run by NCrunch.

Sorry for the confusion, and thanks very much for all your help. I'm up and running now, and looking forwards to trying it out properly.

Cheers,

Rich
Remco
#8 Posted : Thursday, August 15, 2013 12:56:16 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Great! Happy crunching! :)
CarlHA
#9 Posted : Friday, November 22, 2013 6:05:56 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/22/2013(UTC)
Posts: 1
Location: United Kingdom

Hi Remco,

I am experiencing a similar issue around linked files. The project that references the linked file copies it into the bin directory as expected. However, this project is then referenced in the test project and the linked file is not being copied into the bin directory of the test project even with "Copy referenced assemblies to workspace" turned on for all projects.

When I build the test project in Visual Studio the file is copied across. I'm not using build events or anything like that.

Any ideas what the issue may be?

Thanks,
Carl
Remco
#10 Posted : Monday, November 25, 2013 11:38:25 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi Carl -

I suspect this is a hole in NCrunch's build engine. The linked files likely require special handling that right now isn't being performed by the engine. I'll need to take a look at this to see if I can arrange a fix. You may be able to work around the problem by declaring these files as standard 'Copy local' resources or by referencing them using the location of the DLL under test (which would also allow you to avoid using 'Copy referenced assemblies to workspace', thus improving performance).

Sorry for taking so long in replying to your message - it slipped through my net.


Cheers,

Remco
Bart1
#11 Posted : Sunday, June 19, 2016 2:02:28 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 6/19/2016(UTC)
Posts: 1
Location: Bahamas, The

Thanks: 1 times
Remco;4832 wrote:
Hi Carl -

I suspect this is a hole in NCrunch's build engine. The linked files likely require special handling that right now isn't being performed by the engine. I'll need to take a look at this to see if I can arrange a fix. You may be able to work around the problem by declaring these files as standard 'Copy local' resources or by referencing them using the location of the DLL under test (which would also allow you to avoid using 'Copy referenced assemblies to workspace', thus improving performance).

Sorry for taking so long in replying to your message - it slipped through my net.


Cheers,

Remco


Hi!

I just downloaded the trial version and I having the same bug. NCrunch is not copying my files that are added as links.

Is there any time frame to fix this? Without a fix, I don't think I can use NCrunch, although it looks like a great tool.

Thank you very much.
Remco
#12 Posted : Sunday, June 19, 2016 10:37:46 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 7,145

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Bart1;8865 wrote:

Hi!

I just downloaded the trial version and I having the same bug. NCrunch is not copying my files that are added as links.

Is there any time frame to fix this? Without a fix, I don't think I can use NCrunch, although it looks like a great tool.

Thank you very much.


Hi! I'm sorry to hear that you've also been hit by this problem.

A solution is in the works but unfortunately the build it is in is not yet in a state where it is stable enough for a release. I'd suggest working around the problem using some code to manually (re)copy the files in your tests or using a post build event for now. I'll update this thread as soon as I have a way to make the fix available.
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.082 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download