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

Notification

Icon
Error

NCrunch Console Tool Requiring Unneeded Packages
pbassett
#1 Posted : Tuesday, January 19, 2021 8:11:58 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/17/2020(UTC)
Posts: 6

I have a .Net Standard project being built in VS 2019 Build Tools.

After doing a dotnet restore and a build, I run the NCrunch Console tool on its solution.

NCrunch errors complaining about missing packages. The packages that it's complaining about are not needed to build or run it, but NCrunch will not continue without them.

The weird thing, though, is that running NCrunch downloads the packages, so if I then run NCrunch again, it succeeds.

Also, if I add the (unneeded) packages to the project, NCrunch is happy.

Neither of these solutions are ideal. Is there any way to get NCrunch to either A) ignore these packages or B) use the packages that it is downloading?
Remco
#2 Posted : Tuesday, January 19, 2021 11:23:59 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 814 times
Was thanked: 1088 time(s) in 1032 post(s)
Hi, thanks for sharing this issue.

When NCrunch runs, there are two kinds of packages that are needed on the machine:
1. The packages referenced by your projects and the runtime packages needed to execute the code in your projects
2. The packages required by NCrunch for it to work internally

The first packages will likely be restored by your dotnet restore command. However, this won't restore the packages NCrunch needs for itself. To handle that, when it runs, NCrunch will check the package cache for a list of packages it believes may be needed for it to perform the run. It then builds a temporary project that contains references to the missing packages it needs, and runs a dotnet restore command over this project.

Sometimes, on some systems, the dotnet restore command does not work in this situation. We do not know why, but it's reasonable to expect that there may be environmental concerns that block it (i.e. firewalls, virus scanners, security config, etc). This can cause the package restore to fail and NCrunch then runs into trouble downstream. If the system is complaining about a missing package during your run, make sure the correct version of the package is installed in the executing user's package cache. If need be, you can copy it over from another machine.

If your package cache is being redirected (it's possible to do this in a number of ways), then you may see some weird things happen here. For example, it could be that your user's package cache is being piped to a temporary location that gets cleared somehow between runs. Normally I would expect a downloaded package to stay on the machine, but I'm not sure how your infrastructure is configured. I would recommend checking which user account is being used for running your build as this may be having an impact on the storage patterns here.
pbassett
#3 Posted : Thursday, January 21, 2021 4:29:18 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/17/2020(UTC)
Posts: 6

I did some more digging, and this is what I found:

NCrunch is doing an msbuild restore (not a dotnet restore) on project generated by NCrunch. That project is found in C:\Users\[username]\AppData\Local\NCrunch\[TempDir]\PackageRestore\restorePackages.csproj

In my case, this is the contents of that project file:


Quote:

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
<PackageReference Include="xunit.abstractions" Version="2.0.3" />
<PackageReference Include="xunit.runner.utility" Version="2.4.1" />
</ItemGroup>
</Project>


The three packages that are referenced in this file (System.Runtime.Loader 4.3.0, xunit.abstractions 2.0.3, and xunit.runner.utility 2.4.1) are all downloaded when NCrunch calls msbuild.exe \t:restore on restorePackages.csproj

The msbuild restore command completes without errors:
Quote:
6 Warning(s)
0 Error(s)


But immediately after this, NCrunch gives me this error:

Quote:
ERROR: Unable to restore required Nuget packages for .NET Core test environment
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.

Note that the restore of packages may fail if NCrunch is being hosted under a windows account that does not have sufficient rights to store files in the Nuget packages directory.System.Runtime.Loader v4.3.0
System.Runtime.Loader v4.3.0
System.Runtime.Loader v4.3.0
System.Runtime.Loader v4.3.0
System.Runtime.Loader v4.3.0
System.Runtime.Loader v4.3.0
System.Runtime.Loader v4.3.0
System.Runtime.Loader v4.3.0
System.Runtime.Loader v4.3.0
System.Runtime.Loader v4.3.0
xunit.abstractions v2.0.3
xunit.runner.utility v2.4.1


This happens even though the msbuild restore command downloaded all of those files, and they are present in the user's nuget package directory.

Why is it doing this? Could it be a timing issue, where they're still downloading when NCrunch checks on them?

Also, should I be concerned that the target framework of NCrunch's project is netcore 1.0?
Remco
#4 Posted : Thursday, January 21, 2021 4:42:06 AM(UTC)
Rank: NCrunch Developer

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

Thanks: 814 times
Was thanked: 1088 time(s) in 1032 post(s)
pbassett;15259 wrote:

NCrunch is doing an msbuild restore (not a dotnet restore) on project generated by NCrunch. That project is found in C:\Users\[username]\AppData\Local\NCrunch\[TempDir]\PackageRestore\restorePackages.csproj


Correct. Sorry, I remembered that wrong.

pbassett;15259 wrote:

Why is it doing this? Could it be a timing issue, where they're still downloading when NCrunch checks on them?


The most likely situation here is that NCrunch is not looking in the correct place for the installed packages.

Can you confirm which user account you are using for the run, and where your Nuget package root is? Usually this is under C:\Users\USER\.nuget\packages.

pbassett;15259 wrote:

Also, should I be concerned that the target framework of NCrunch's project is netcore 1.0?


When we implemented support for .NET Core under NCrunch, 1.0 was all there was. Our testing so far shows that this should make no difference.
pbassett
#5 Posted : Thursday, January 21, 2021 2:48:34 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/17/2020(UTC)
Posts: 6

NCrunch is being run as user sa-buildsvr.

The packages are downloaded to C:\Users\sa-buildsvr\.nuget\packages
Remco
#6 Posted : Thursday, January 21, 2021 11:11:28 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 814 times
Was thanked: 1088 time(s) in 1032 post(s)
pbassett;15263 wrote:

The packages are downloaded to C:\Users\sa-buildsvr\.nuget\packages


Can you confirm whether the correct versions of the required packages are stored in this directory? If not, does copying the packages in there (i.e. from another machine) resolve the issue?
pbassett
#7 Posted : Monday, January 25, 2021 3:00:51 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 11/17/2020(UTC)
Posts: 6

Yes, the correct versions of the required packages are downloaded to c:\users\sa-buildsvr\.nuget\packages.

If the packages are already there before NCrunch is run, NCrunch runs fine.

If they're not there, NCrunch will download them, and then fail because it says it couldn't download them.
Remco
#8 Posted : Monday, January 25, 2021 11:31:11 PM(UTC)
Rank: NCrunch Developer

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

Thanks: 814 times
Was thanked: 1088 time(s) in 1032 post(s)
pbassett;15269 wrote:

If they're not there, NCrunch will download them, and then fail because it says it couldn't download them.


Do you have the option of pre-copying the packages and leaving them there?

At the moment, the only reason I can think of why they wouldn't be there would be if the msbuild /t:restore step was malfunctioning internally.
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.066 seconds.
Trial NCrunch
Take NCrunch for a spin
Do your fingers a favour and supercharge your testing workflow
Free Download