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

Notification

Icon
Error

Console Tool Not Building .Net Standard Library
Christian Moritz
#1 Posted : Tuesday, March 26, 2019 9:30:34 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/26/2019(UTC)
Posts: 8
Location: Switzerland

Thanks: 1 times
Hello

We are using NCrunch for a solution with just over 100 projects.
The developers use it locally in Visual Studio 2017 and on the TFS-build-machine we use the console tool to run the tests.

Our architect decided that sooner or later we should move from the old .NET Framework to .NET Core/Standard.
So some of our new projects should already be .NET Standard libraries.

This seems to be a problem for NCrunch.
The visual studio version complained about NuGet-Packages that could not be restored after I added the first .NET Standard project.
The packages it complained about were packages that none of our projects used.
The solution was to let NCrunch ignore these projects.

Now I have added a new .NET Standard project.
This is not a test-project and there is no corresponding test-project either, so the first instinct was to ignore it as well.
However it is referenced by an other (old .NET Framework) project.
That in turn is tested in a test-project.
So ignoring the .NET Standard project is not a solution, as the the .NET Framework project will not build and the test-project will fail as well.
But luckily this project doesn't give us any trouble in Visual Studio.

On our build machine or using the console tool on my own machine the NCrunch console tool throws an exception.
The build machine does not have Visual Studio installed, just msbuild. Could this explain the exception below?


Exception on build machine without Visual Studio installed:
Quote:
2019-03-26T03:20:37.7147585Z [04:20:37.4333-Core-7] All projects have been loaded
2019-03-26T03:20:37.7203889Z [04:20:37.7144-Core-7] ERROR (Internal): System.NullReferenceException: Object reference not set to an instance of an object.
2019-03-26T03:20:37.7204343Z at nCrunch.Core.PlatformTypes.DotNetCore.DotNetCorePlatformType.(VisualStudioVersion )
2019-03-26T03:20:37.7204636Z at nCrunch.Core.PlatformTypes.DotNetCore.DotNetCorePlatformType.AllProjectsLoaded(VisualStudioVersion vsVersion)
2019-03-26T03:20:37.7204920Z at nCrunch.Client.Synchronisation.SnapshotSynchroniser.()
2019-03-26T03:20:37.7205168Z at nCrunch.Client.Synchronisation.SnapshotSynchroniser.(DteProjectsAddedWithBuildXmlEvent )


Locally I have Visual Studio but it fails at some later point.

Exception on my machine with Visual Studio installed:
Quote:
[09:45:40.9804-Core-7] All projects have been loaded
[09:45:40.9974-Core-7] ERROR (Internal): System.ComponentModel.Win32Exception (0x80004005): The system can not find the file specified
bei System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
bei nCrunch.Core.PlatformTypes.DotNetCore.MSBuildCommandTool.Invoke(DirectoryPath workingDirectory, String commandLine)
bei nCrunch.Core.PlatformTypes.DotNetCore.DotNetCoreSdk.RestorePackages(FilePath projectFilePath, VisualStudioVersion vsVersion)
bei nCrunch.Core.PlatformTypes.DotNetCore.DotNetCorePlatformType.(VisualStudioVersion )
bei nCrunch.Core.PlatformTypes.DotNetCore.DotNetCorePlatformType.AllProjectsLoaded(VisualStudioVersion vsVersion)
bei nCrunch.Client.Synchronisation.SnapshotSynchroniser.()
bei nCrunch.Client.Synchronisation.SnapshotSynchroniser.(DteProjectsAddedWithBuildXmlEvent )


Short of turning all our .NET Standard projects into .NET Framework project, how can we get the console tool to work with our solution?
What can I try to solve this problem?
What can I do to find out what really goes wrong?

Seems I was wrong about the Visual Studio version not giving us any trouble.
The error just returned.
Quote:
NCrunch was unable to restore Nuget packages required to build a test environment for this solution, due to an unspecified failure when invoking 'msbuild.exe /t:restore'

The following packages do not exist under the Nuget packages folder for the active user profile, yet they have been flagged by NCrunch as potentially needed for normal operation. NCrunch has attempted to restore these files via an MSBuild restore step, which has either failed or not returned the expected result. It's possible that these packages may not be needed for building projects or running tests in your environment. If you experience downstream problems with NCrunch on this solution, it is recommended you restore or download the packages manually.

xunit.abstractions v2.0.1
xunit.runner.utility v2.2.0

We are not using xunit, so why should we include xunit-packages?


I hope someone can help me solve this.

Thank you
Remco
#2 Posted : Tuesday, March 26, 2019 11:25:32 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Hi, thanks for sharing these problems.

.NET Core/Standard has a very different build model to .NET Framework in that it is heavily dependent on Nuget and associated tooling. Bindings to packages must be directed through the Nuget system as we cannot guarantee that a package is actually present on the machine responsible for the build. For this reason, NCrunch needs to invoke MSBuild to ensure packages are properly restored. If this step fails, there's quite a bit that can go wrong.

NCrunch is dependent on being able to invoke MSBuild.exe from the following location (varies slightly depending on VS SKU etc):
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe

This is done in the context of the NCrunch.EngineHost process.

In your environment, the O/S rejects the process invocation. This might be because the file is not in the expected place, or it is corrupt, or something is blocking the invocation (i.e. virus scanner, security settings, etc). Unfortunately I have no way to analyse this because it seems to be specific to your environment. I recommend checking that MSBuild is installed correctly and you're able to execute it via a non-administrative command line prompt. Also try temporarily disabling any security settings or scanners that may obstruct it.

The Nuget restore step executed indirectly by MSBuild also requires a network connection to Nuget to be able to restore the packages. There are things that can block this (i.e. security settings, firewall). This may not be a deal breaker if you already have the required packages installed, but NCrunch will likely warn you if it can't download packages that it might need downstream.

Christian Moritz;13268 wrote:

On our build machine or using the console tool on my own machine the NCrunch console tool throws an exception.
The build machine does not have Visual Studio installed, just msbuild. Could this explain the exception below?

Exception on build machine without Visual Studio installed:
Quote:
2019-03-26T03:20:37.7147585Z [04:20:37.4333-Core-7] All projects have been loaded
2019-03-26T03:20:37.7203889Z [04:20:37.7144-Core-7] ERROR (Internal): System.NullReferenceException: Object reference not set to an instance of an object.
2019-03-26T03:20:37.7204343Z at nCrunch.Core.PlatformTypes.DotNetCore.DotNetCorePlatformType.(VisualStudioVersion )
2019-03-26T03:20:37.7204636Z at nCrunch.Core.PlatformTypes.DotNetCore.DotNetCorePlatformType.AllProjectsLoaded(VisualStudioVersion vsVersion)
2019-03-26T03:20:37.7204920Z at nCrunch.Client.Synchronisation.SnapshotSynchroniser.()
2019-03-26T03:20:37.7205168Z at nCrunch.Client.Synchronisation.SnapshotSynchroniser.(DteProjectsAddedWithBuildXmlEvent )



Can you confirm that you have the relevant version of the .NET Core SDK installed on this machine?

Quote:

We are not using xunit, so why should we include xunit-packages?


At this early stage of bootstrapping the engine, NCrunch doesn't yet know whether the xunit packages are required or not. They are listed internally as dependencies for NCrunch as a whole, because before we can load the necessary adapters to determine whether you're using xunit tests, we need to have every set up first. You can probably ignore this error. If you want to get rid of it, you can create a small sample project on your machine and add package dependencies to these packages so that Nuget will restore them into your package cache. Fixing the issue with MSBuild invocation/restoration will also likely fix this, because then NCrunch will just quietly restore these packages itself.


Edit: Can you also confirm that you're using the latest version of NCrunch and the latest version of VS2017?
Christian Moritz
#3 Posted : Wednesday, March 27, 2019 6:43:15 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/26/2019(UTC)
Posts: 8
Location: Switzerland

Thanks: 1 times
Hi, thanks for the answer.

On my machine the msbuild.exe is exactly where you said it should be.
I can execute it via a non-administrative command line prompt.
As it works for everything else, I doubt it is corrupt.
I turned off the firewall and got the same error.

We are using Visual Studio Enterprise 2017 version 15.9.10 and NCrunch 3.24.0.5.
Unless you release a new NCrunch version after I write this line or Microsoft does that for Visual Studio, those are the latest versions.
I installed the .NET Core SDK version 2.2.105, that should also be the latest stable version.

I don't have access to the build machine, but will ask the administrator to check out things there.
Would the different error we get on the build machine be explained by the fact, that it does not have Visual Studio but only MsBuild and the SDKs etc. installed?

What I did is to include a NuGet.config that forces the packages into the local packages folder instead of the one in the user profile.
That took away a lot of those messages about packages that can not be restored.
I considered creating a dummy-project to include the references. But that is a last resort solution, I was hoping to get it to work without a workaround (definitely not a word you should use around some of my colleagues).

Is there anything else we could try?

Edit: I checked with the administrator. The paths and versions on the build machine are correct and the firewall was turned off.
Remco
#4 Posted : Wednesday, March 27, 2019 11:37:09 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks for your patience here.

Something that I think would be worth trying on your machine is to create a small sample .NET Standard project with a .NET Core test project, then try running NCrunch over it and seeing if it fails.

This will help to determine whether the problem is triggered by something in your environment, or whether it's project specific. There is a possibility that it's being caused by a specific package or a referenced version of .NET Core/Standard.

Quote:

Would the different error we get on the build machine be explained by the fact, that it does not have Visual Studio but only MsBuild and the SDKs etc. installed?


This is absolutely a possibility. We have tested this scenario and to my knowledge it should work, but we don't test it as frequently as other use cases and the toolset is changing all the time. It may be worth installing a version of VS on the machine to see if this has any impact on the behaviour. If it does, we'll have a vital clue that might help us reproduce and resolve it.
Christian Moritz
#5 Posted : Thursday, March 28, 2019 6:50:11 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/26/2019(UTC)
Posts: 8
Location: Switzerland

Thanks: 1 times
Hello

As was to be expected, the small sample project works of course.
Why couldn't it be easy to analyse a problem like that just once?
Now I will have to find out which of our over 100 projects combined with the .NET Standard project leads to the failure.
That could take weeks.

I noticed two things in the report generated by the console tool.

There is a warning about the MsBuild version, when it is build on one of our Grid Node Servers:
Quote:
WARNING - NCrunch: This project has been built with MSBuild v15.0 because MSBuild vCurrent was not found on this server. Some build tasks may fail when not executed using the correct version of MSBuild.

How can I find out what "vCurrent" is? Should that be v15.9, as the version of the exe on my local machine is?

If I understand this message correctly the actual build process is executed on the Grid Node Server. Those do have Visual Studio installed and are up to date (according to the administrator).
I thought it might have been the build machine, that actually gets the sources, builds them and triggers the NCrunch Console Tool to execute the tests on the Grid Node Servers.

The second thing I noticed is the following message in the report for the .NET Standard project:
Quote:
NCrunch: The following files were used when building this project locally but do not seem to exist on the remote grid node responsible for building this project:

After that every single dependency and their dependencies are listed, with a path in my local user folder.

I have to check whether we actually get to invest the time to investigate further.
I will get back to you if we find out any more.
Remco
#6 Posted : Thursday, March 28, 2019 7:47:34 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Christian Moritz;13278 wrote:

Why couldn't it be easy to analyse a problem like that just once?


We've had .NET Core and .NET Standard support in NCrunch for about two years now. This means that if there's a problem that's simple to analyse and/or is impacting many people, we're certain to have solved it already. The issues we're getting now tend to be more due to platform changes or very niche edge cases caused by less common configuration. This does, unfortunately, mean you are very unlucky. You've been hit with a problem that we haven't seen before and we haven't found a way to recreate it.

The only real way to progress from here is for you to deductively identify how to reproduce the problem in a sample solution. From there, we can almost certainly provide you with a fix or advice on how to resolve the issue. Sorry, if I had another option, I would honestly suggest it :(

Christian Moritz;13278 wrote:

There is a warning about the MsBuild version, when it is build on one of our Grid Node Servers:
Quote:
WARNING - NCrunch: This project has been built with MSBuild v15.0 because MSBuild vCurrent was not found on this server. Some build tasks may fail when not executed using the correct version of MSBuild.

How can I find out what "vCurrent" is? Should that be v15.9, as the version of the exe on my local machine is?


This is very interesting. It says that the tool is first trying to use the build tools from VS2019 before it falls back to MSBuild 15 (which is VS2017). Have any VS2019 components ever been installed on this machine?

Christian Moritz;13278 wrote:

If I understand this message correctly the actual build process is executed on the Grid Node Server. Those do have Visual Studio installed and are up to date (according to the administrator).
I thought it might have been the build machine, that actually gets the sources, builds them and triggers the NCrunch Console Tool to execute the tests on the Grid Node Servers.


The Console Tool needs to perform a partial build to analyse the project file and resolve its dependencies. Under .NET Core, it also needs some level of platform integration to resolve packages. This does unfortunately introduce a dependency on MSBuild.

Christian Moritz;13278 wrote:

The second thing I noticed is the following message in the report for the .NET Standard project:
Quote:
NCrunch: The following files were used when building this project locally but do not seem to exist on the remote grid node responsible for building this project:

After that every single dependency and their dependencies are listed, with a path in my local user folder.


This is technically not an error message. When a build fails like this, NCrunch will cross-check the targets so that it might be more obvious when an SDK is missing on the machine. If you're confident you have everything you need already installed, then the information here is not useful.
Christian Moritz
#7 Posted : Thursday, March 28, 2019 8:26:24 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/26/2019(UTC)
Posts: 8
Location: Switzerland

Thanks: 1 times
Thanks for the quick answer.

On a hunch I tried running the console tool for our solution one more time, after it worked for the small project.
And suddenly it worked. Something the administrator did on the Grid Node machines (whatever that was, one of them seemed to be a bit off, so he cloned of the the others), must have fixed it.

Unfortunately it only worked on my machine, on our build machine it still fails, with the same Exception.


I checked with the administrator. There has never been any Visual Studio 2019 component on either the build agent machine or any of the Grid Node machines.

Although he doesn't like the idea, he is going to install Visual Studio 2017 on the build agent machine, to see if that solves the problem.
Christian Moritz
#8 Posted : Friday, March 29, 2019 5:32:09 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/26/2019(UTC)
Posts: 8
Location: Switzerland

Thanks: 1 times
Visual Studio has now been installed on the build agent.
That actually got rid of the NullReferenceException.
But now we get the same Win32Exception, quoted in my first post, I got on my own machine.


I didn't do anything on my own machine to fix this.
I just tried a small project as you suggested and it worked, after that it worked for our big project as well.
I only got a message indicating that the console tool could not access the folder where it writes its report, but the tests where executed.
I solved that by starting the console tool as administrator.
We never had that problem on the build agent (when it still worked, before we had any .NET Standard projects), so should not be a problem there.

As I didn't install or update any component on my machine and the grid node servers are the same, there must be something else missing on the build agent.
On my machine that was the step where the ncrunch console tool actually connected to the first grid node server.
What could be missing on the build agent that it throws this exception?
Remco
#9 Posted : Friday, March 29, 2019 10:28:51 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Would you be able to obtain for me a detailed log of the console tool's execution run up to the point where it fails?

You can do this by running the tool with the '-LogVerbosity Detailed' parameter and piping the result to a file. You can ZIP the file up and submit it through the contact form.
Christian Moritz
#10 Posted : Monday, April 1, 2019 11:25:34 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/26/2019(UTC)
Posts: 8
Location: Switzerland

Thanks: 1 times
We hoped to get the regular NCrunch console tool report, but didn't get that, as the build ran into a timeout after 120 minutes.
TFS cancelled everything and the NCrunch report wasn't even created.

I have send the detailed output as logged in TFS via the contact form.
While it is far more detailed it unfortunately does not show the exception we get without the '-LogVerbosity Detailed' parameter.

I hope you see something in the log that will help us find a solution to this problem.
Remco
#11 Posted : Tuesday, April 2, 2019 1:23:49 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Looking at the log, the tool wasn't able to reach the point in its processing where the failure was able to occur.

Could you perhaps try with '-LogVerbosity Medium' instead?
Christian Moritz
#12 Posted : Tuesday, April 2, 2019 10:05:10 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/26/2019(UTC)
Posts: 8
Location: Switzerland

Thanks: 1 times
I just send the log with the verbosity medium via the contact form.
It took a while as the administrator got in just after I had the log and we decided to update NCrunch to the just released version and run the build again. (That didn't magically fix it.)

It shows the internal error on line 36643.

We have some other problems with the .NET Standard projects and a couple of guys that are not really happy with mixinig .NET Core/Standard with .NET Framework here.
So we decided that for now it is not worth the effort and will be going back to .NET Standard.
After that the NCrunch console tool will most likely not give us any more trouble.

If this is actually a problem in NCrunch and not our solution, I hope this will give you a clou as to what is going wrong and a way to fix it.
Remco
#13 Posted : Wednesday, April 3, 2019 2:05:38 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks for sending through the log.

I've identified the source of this problem. The NCrunch console tool is not correctly considering the installation state of the supported VS versions, so it's just using the highest version of VS that we've implemented, regardless of whether it is actually installed. This gives a downstream exception.

We're working on a fix for this in the next version of NCrunch. For now, the best workaround is to always specify the version of VS you are using with the '/VS' command line parameter.

Note that I'm still not sure what is causing the Win32Exception. I'd be happy to look into this in more detail if you are able to get me a log of this happening.

I don't expect that porting such a large solution to .NET Core would be an easy task.. We've certainly had our own fun with this platform.
1 user thanked Remco for this useful post.
Christian Moritz on 4/3/2019(UTC)
Christian Moritz
#14 Posted : Wednesday, April 3, 2019 6:07:31 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/26/2019(UTC)
Posts: 8
Location: Switzerland

Thanks: 1 times
I just started a build with the /VS command line parameter.
The build is not done yet, but the NCrunch steps are done.
So the command line parameter worked.


It would be nice if the documentation of the console tool listed and explained the command line parameters.
There are two articles about the console tool in the documentation, but they both just link to the other one for details about the usage.

Tools/Console Tool: "For a full setup and usage guide, see the console tool usage guide."
Guides/Console Tool Usage: "For more detailed information about the tool, please refer to the console tool documentation."


The Win32Exception only happened once on my machine and once on the build machine.
So it seems to be some rare thing.
It seemed to happen just a bit later in the stack than the NullReferenceException.
So possibly the code somehow got past the point where the NullReferenceException happens and crashes two or three steps after that.


Thanks
Remco
#15 Posted : Wednesday, April 3, 2019 11:53:59 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 959 times
Was thanked: 1290 time(s) in 1196 post(s)
Thanks for the feedback. I think there's a chance that the Win32Exception is downstream from the other one. Let me know if you can get a log of it happening without the other exception involved.
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.173 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download