Build/Test Issues

Easy way to copy an additional file to the _ncrunchreferences folder?

Started by mortan on 8,841 views

Hi!

My projects are referencing a nuget package that contains an assembly and a configuration file. On build both files are copied to the bin\Debug\ folder and everything works (assembly is loading the configuration file relative to its file path). Using ncrunch the referenced assembly is placed in the _ncrunchreferences folder but not so the configuration file.

I figured out that setting "Copy referenced assemblies to workspace" works (config file gets copied to the same place as the assembly) but makes the bin\Debug folder inside my ncrunch workspace explode. I tried the "Include additional files" setting, but the config file ends up in the wrong place (not in the _ncrunchreferences folder).

I'm wondering if there is an easy way to copy the config file to the right place without enabling "Copy referenced assemblies to workspace"...


Help appreciated! :)

Kind regards!
Hi, thanks for posting!

Unfortunately the 'Copy referenced assemblies to workspace' setting is intended to be the solution to this problem. The setting can't differentiate between the file you need and the files you don't, so it just copies them all as per normal build behaviour.

What sort of config file is being copied? Is it perhaps possible to have some code running at the beginning of every test (or as a SetUpFixture) that can copy the file into the expected place as a workaround?
Hi Remco!

Copying the file to the ncrunchreferences directory in a SetUpFixture method could work, but it's not something I would like to do (hard wire the unit tests to ncrunch feels very wrong to me).

I was searching for an option to specify the output folder in the "Include additional files"... unfortunately there is none. :( That would be the most appropriate solution in my opinion. I mean "Copy referenced assemblies to workspace" works... it just slows down the process a bit and I think that including a nuget package that consists of a dll and a configuration file for this dll is not *that* uncommon!

Regards!
Sorry :( I've suggested the only options that I know will solve this problem. There isn't an in-between in terms of the Copy referenced assemblies behaviour - this is all controlled by MSBuild rather than NCrunch. When the setting is disabled, NCrunch just suppresses the entire set of behaviour.

You could always use '#if NCRUNCH' if you want to implement a workaround and avoid running the code for non-NCrunch runners.
Ah I see. Well if it is a limitation coming from MSBuild I will stick with the "Copy referenced assemblies to workspace" option.

Maybe you got an idea for this issue of mine?

Thanks for your help! :)

Edited

Hi,
Here is code to copy file from bin to _ncrunchreferences.
I had problems running EVO HTML to PDF Converter for .NET with error:
System.Exception: Could not start conversion. WinApi error code 2. Check 'evointernal.dat' file has execute permissions and that it exists near evohtmltopdf.dll or set the EvoInternalFileName property with the full path of the file


        static void SetupNCrunch()
        {
#if NCRUNCH
            var pathTo = NCrunch.Framework.NCrunchEnvironment.GetAllAssemblyLocations()
                .Single(x => x.EndsWith("evohtmltopdf.dll", StringComparison.InvariantCultureIgnoreCase))
                .Replace("evohtmltopdf.dll", "evointernal.dat");
            var pathFrom = Path.Combine(Path.GetDirectoryName(NCrunch.Framework.NCrunchEnvironment.GetOriginalProjectPath()), @"bin\Debug\evointernal.dat");

            if (!File.Exists(pathTo))
                File.Copy(pathFrom, pathTo);

            //nuget Install-Package FluentAssertions
            pathFrom.Should().Be(@"C:\VSC\project\src\AcceptanceTests\bin\Debug\evointernal.dat");
            File.Exists(pathFrom).Should().BeTrue();

            pathTo.Should()
                .StartWith(@"C:\Users\name\AppData\Local\NCrunch\")
                .And.EndWith(@"\_ncrunchreferences\evointernal.dat");
            File.Exists(pathTo).Should().BeTrue();
#endif
        }

Edited

Post a reply

Log in to reply.