Build/Test Issues

Include as link not copied to NCrunch output?

Started by GreenMoose on 8,871 views

[v3.12.0.15]

I have a nlog config file in directory A, then I include it "as link" in my test project, and set it to be copied to output if newer, resulting in something like below

<ItemGroup>
<None Include="..\CommonFiles\nlog.config" Link="nlog.config">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>


When I build this with vstudio I see the nlog.config ending up in output directory, but when NCrunch is building it is not placed in the NCrunch workspace directory and the tests fail.

If I include the file "normally" (without as link) it all works well.

Is this behavior by design?
Thanks.

Edited

Hi, thanks for sharing this issue.

I'm personally unfamiliar with this mechanism (link). Historically, MSBuild has had support for specifying a 'link' file using an XML tag, but this is the first time I've seen it done as an attribute. So probably the reason NCrunch doesn't handle it would be because it's an edge case that has seen no testing or support.

How is it that you've come across this structure? Was this done using a tool or project template?
Remco wrote:How is it that you've come across this structure? Was this done using a tool or project template?

I usually do like this when sharing same AssemblyInfo.cs files in multiple projects (which I guess works fine since that file is included in compile process), and now I had duplicated config files I wanted to share in the same way

I.e. no tooling or template, Add->existing item-> select "Add as link" instead of "Add"
[img=https://i.imgur.com/dIzfBGN.png]Add as link[/img]
GreenMoose wrote:
I usually do like this when sharing same AssemblyInfo.cs files in multiple projects (which I guess works fine since that file is included in compile process), and now I had duplicated config files I wanted to share in the same way

I.e. no tooling or template, Add->existing item-> select "Add as link" instead of "Add"
[img=https://i.imgur.com/dIzfBGN.png]Add as link[/img]


Thanks! We'll take a look and see what we can do.
Hi, I've had a look at reproducing this issue. I've created a new ClassLibrary and created a Linked item which shows up in the the project file like this:


  <ItemGroup>
    <None Include="..\CommonFiles\LinkedTextFile.txt">
      <Link>LinkedTextFile.txt</Link>
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>


This item is below the project level, but inside the solution. I've added a unit test to the assembly.


    public class Fixture
    {
        [Test]
        public void LinkedFileShouldExist()
        {
            Assert.That(File.Exists(@"LinkedTextFile.txt"));
        }
    }


This test passes. Also I double checked the NCrunch workspace. The file is also present there.

Would you mind seeing if you create a test project like this that it works for you?
I used a dotnetCore library for the test though which I guess maybe is the culprit of including it as an attribute?
Thanks for getting back so quickly!

I've tried adding a dotnet core class library.


  <ItemGroup>
    <None Include="..\CommonFiles\LinkedTextFile.txt" Link="LinkedTextFile.txt">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>


This indeed adds the link as an attribute. However in my test project the file is also copied to the work space and a similar test case also passes.
michaelkroes wrote:However in my test project the file is also copied to the work space and a similar test case also passes.

Hrm yeah it works here as well now when I retry the setup. I guess it might have been related to some other NCrunch internal errors I was having (bug reports submitted) related to projects not reloaded properly.

Thanks.

Post a reply

Log in to reply.