nimbleways / dotnet-subset

A .NET tool that copies a subset of files from a repository to a directory. The tool is mainly used in Dockerfiles to optimize the docker build caching for "dotnet restore" instructions.
MIT License
88 stars 4 forks source link

Unhandled exception. System.InvalidOperationException: No instances of MSBuild could be detected #6

Open nbsoftware opened 1 year ago

nbsoftware commented 1 year ago

On macOS (M1 Max) trying to run it locally I'm getting:

Unhandled exception. System.InvalidOperationException: No instances of MSBuild could be detected.
Try calling RegisterInstance or RegisterMSBuildPath to manually register one.
   at Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults()
   at Program.<Main>$(String[] args) in /home/runner/work/dotnet-subset/dotnet-subset/src/dotnet-subset/Program.cs:line 12

I have latest dotnet 6 & 7 sdks installed:

6.0.403 [/usr/local/share/dotnet/sdk]
6.0.404 [/usr/local/share/dotnet/sdk]
7.0.100 [/usr/local/share/dotnet/sdk]
7.0.101 [/usr/local/share/dotnet/sdk]
7.0.102 [/usr/local/share/dotnet/sdk]

What can be the issue?

othmane-kinane-nw commented 1 year ago

I will have to get my hands on a MacBook to try to reproduce. Maybe later this week.

In the meanwhile, I'm curious about your use case, can you tell me more ? dotnet-subset is usually run within a linux container.

nbsoftware commented 1 year ago

Correct,

But because I was given some incorrect syntax error when used directly from my dockerfile and also because I wanted to look and understand what it generates I tried to run it locally against my csproj.

I'll try harder in my dockerfile then for now, but you've got to admit this isn't the most convenient way to inspect / debug :)

othmane-kinane-nw commented 1 year ago

I agree. I'll look into it.

othmane-kinane-nw commented 1 year ago

I tested on a MacBook Pro x86, could not reproduce the problem. Here is what I tried:

  1. downloaded and installed .NET SDK 7. dotnet --list-sdks shows 7.0.102 [/usr/local/share/dotnet/sdk]
  2. installed dotnet-subset with the command: dotnet tool install --global dotnet-subset --version 0.3.1
  3. cloned the repository https://github.com/kgrzybek/modular-monolith-with-ddd
  4. from the repository root, I ran: dotnet subset restore src/API/CompanyName.MyMeetings.API/CompanyName.MyMeetings.API.csproj --root-directory . --output /myOutputFolder
  5. command ran successfully, with this line as last log: Copied 21 file(s) to '/myOutputFolder. ....'

Can you try following these instructions with the suggested repo (modular-monolith-with-ddd) ?

nbsoftware commented 1 year ago
modular-monolith-with-ddd git:(master) dotnet subset restore src/API/CompanyName.MyMeetings.API/CompanyName.MyMeetings.API.csproj --root-directory . --output /myOutputFolder
Unhandled exception. System.InvalidOperationException: No instances of MSBuild could be detected.
Try calling RegisterInstance or RegisterMSBuildPath to manually register one.
   at Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults()
   at Program.<Main>$(String[] args) in /home/runner/work/dotnet-subset/dotnet-subset/src/dotnet-subset/Program.cs:line 12

Exact same issue which is expected as the problem is right from the start.

Might have to do with https://github.com/microsoft/MSBuildLocator/issues/153

But I had a look at your csproj... all package references are quite old. Updating them all and targeting .net 6 might do the trick...

OKinane commented 1 year ago

Package whose version is $(MSBuildPackagesVersion) are only used in compile time, Microsoft.Build.Locator is in charge of providing them at runtime.

That being said, dotnet-subset is 2 versions behind for Microsoft.Build.Locator. I'll upgrade in a separate branch. Will you be able to test by building from upgrade branch when it will be ready ? Instructions are in the README.md

nbsoftware commented 1 year ago

Package whose version is $(MSBuildPackagesVersion) are only used in compile time, Microsoft.Build.Locator is in charge of providing them at runtime.

Yes, and that's where I suspect bugs might have been fixed since.

That being said, dotnet-subset is 2 versions behind for Microsoft.Build.Locator. I'll upgrade in a separate branch. Will you be able to test by building from upgrade branch when it will be ready ? Instructions are in the README.md

Sure

nbsoftware commented 1 year ago

Any news on your side?

othmane-kinane-nw commented 1 year ago

@nbsoftware I managed to reproduce the bug and deployed a new version with the fix (https://www.nuget.org/packages/dotnet-subset/0.3.2).

Can you please try again and tell me if it works for you ?

othmane-kinane-nw commented 1 year ago

@nbsoftware did you get the chance to test the new version ?

nbsoftware commented 1 year ago

Hey. Not yet. Will try before end of week.

othmane-kinane-nw commented 1 year ago

@nbsoftware I'll close this issue for now. You can reopen it or create a new one if the problem persists.

nbsoftware commented 1 year ago

Hello. Sorry for this late response. Unfortunately it is not fixed on my machine :/ Why is it using .NET 3.x runtime which I have not installed? Do you need to include the runtime in the distibution?

➜  modular-monolith-with-ddd git:(master) dotnet subset restore src/API/CompanyName.MyMeetings.API/CompanyName.MyMeetings.API.csproj --root-directory . --output ./myOutputFolder
dotnet-subset 0.3.2 (.NET Runtime 3.1.31)
Unhandled exception. System.InvalidOperationException: No instances of MSBuild could be detected.
Try calling RegisterInstance or RegisterMSBuildPath to manually register one.
   at Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults()
   at Program.<Main>$(String[] args) in /home/runner/work/dotnet-subset/dotnet-subset/src/dotnet-subset/Program.cs:line 14
othmane-kinane-nw commented 1 year ago

@nbsoftware can you post the result of dotnet --info ? The log suggests you are using .NET Core 3.1

nbsoftware commented 1 year ago

Well, as I said it doesn't seem to be installed locally. Is it not provided / included within the tool's distribution package?

➜  ~ dotnet --info
.NET SDK:
 Version:   7.0.102
 Commit:    4bbdd14480

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.2
 OS Platform: Darwin
 RID:         osx.13-arm64
 Base Path:   /usr/local/share/dotnet/sdk/7.0.102/

Host:
  Version:      7.0.2
  Architecture: arm64
  Commit:       d037e070eb

.NET SDKs installed:
  6.0.403 [/usr/local/share/dotnet/sdk]
  6.0.404 [/usr/local/share/dotnet/sdk]
  6.0.405 [/usr/local/share/dotnet/sdk]
  7.0.100 [/usr/local/share/dotnet/sdk]
  7.0.101 [/usr/local/share/dotnet/sdk]
  7.0.102 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.13 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
  x64   [/usr/local/share/dotnet/x64]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
othmane-kinane-nw commented 1 year ago

dotnet-subset is distributed as a framework-dependent application, so it's supposed to use a .NET Runtime installed on your machine.

In the latest version that should have fixed the bug, I changed the behavior of the Runtime selection algorithm to choose the latest available version (thanks to the <RollForward>LatestMajor</RollForward> property in the csproj). I did so because of a weird behavior in MsBuildLocator that fail to register if the currently used runtime has a Major.Minor version lower than the latest SDK installed. So aligning the two fixed the problem in my case.

So the one-million-dollar question is why dotnet-subset is running on a .NET Runtime that doesn't even show on dotnet --info. I will investigate this, and I may need your help for a live debugging session.

nbsoftware commented 1 year ago

From https://learn.microsoft.com/en-us/dotnet/core/tools/troubleshoot-usage-issues they say:

If you think the tool should support the runtime version you currently have installed, you can contact the tool author and see if they can update the version number or multi-target. Once they've recompiled and republished their tool package to NuGet with an updated version number, you can update your copy. While that doesn't happen, the quickest solution for you is to install a version of the runtime that would work with the tool you're trying to run.

I believe the solution lies in multi-targeting...

Also I find it a bit weird that you depend on .NETCoreApp,Version=v2.1 in your package.lock.json file...

othmane-kinane-nw commented 1 year ago

The issue here is not runtime compatibility, but runtime selection.

as for 2.1, dotnet-subset doesn't use any feature requiring a version newer than 2.1, that's why I'm targetting it.

Again, the situation is not clear as I can't reproduce this time the problem. I installed 3.1 on my machine, but:

nbsoftware commented 1 year ago

Ok so I think I nailed it:

➜  ~ ls -l /usr/local/share/dotnet/x64/shared/Microsoft.NETCore.App
total 0
drwxr-xr-x  190 root  wheel  6080 Jun 16  2022 3.1.27
drwxr-xr-x  190 root  wheel  6080 Jul 13  2022 3.1.28
drwxr-xr-x  190 root  wheel  6080 Aug 18  2022 3.1.29
drwxr-xr-x  190 root  wheel  6080 Sep 26 22:30 3.1.30
drwxr-xr-x  190 root  wheel  6080 Oct 14 02:26 3.1.31
➜  ~ which dotnet
/usr/local/share/dotnet/dotnet

So let me see why it seems to prefer the x64 version here...

othmane-kinane-nw commented 1 year ago

Interesting ! I found this thread that may explain the situation: https://github.com/dotnet/sdk/issues/22380

What does this command dotnet --version show you ?

nbsoftware commented 1 year ago

So I do think your tool is architecture dependant.

I removed all x64 runtimes installed locally (must have been installed from the early days I got this arm machine). And now I get this, which makes a lot more sense now:

➜  ~ dotnet tool install --global dotnet-subset
Skipping NuGet package signature verification.
You can invoke the tool using the following command: dotnet-subset
Tool 'dotnet-subset' (version '0.3.2') was successfully installed.
➜  ~ dotnet-subset
You must install .NET to run this application.

App: /Users/fmeyer/.dotnet/tools/dotnet-subset
Architecture: x64
App host version: 7.0.3
.NET location: Not found

Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=osx.13-x64&apphost_version=7.0.3
nbsoftware commented 1 year ago

Another interesting article: https://github.com/dotnet/sdk/issues/26417

This is why you might want to target .NET 6.0 - from what I understood

othmane-kinane-nw commented 1 year ago

Ok, so it's definitely a bug in dotnet tool install as said here https://github.com/dotnet/sdk/issues/26417#issuecomment-1172693196 A reply from 4 days ago suggested specifying the arch in install command as a workaround. Can you test it ?

  1. dotnet tool uninstall --global dotnet-subset
  2. dotnet tool install --global --arch arm64 dotnet-subset

In the meanwhile, I will work on multitargeting .NET 2.1 and .NET 6 to avoid having to specify the arch during install.

nbsoftware commented 1 year ago

The suggestion is indeed working - see below. Multi targeting is the route to ease thing, although I'm not sure why you would want to keep .NET 2.1 (which has reached EOL)... if you were to target .NET 6.0 only it would work out of the box without having to multi target.

➜  ~ dotnet tool uninstall --global dotnet-subset
Tool 'dotnet-subset' (version '0.3.2') was successfully uninstalled.
➜  ~ dotnet tool install --global --arch arm64 dotnet-subset
Skipping NuGet package signature verification.
You can invoke the tool using the following command: dotnet-subset
Tool 'dotnet-subset' (version '0.3.2') was successfully installed.
➜  ~ dotnet-subset
dotnet-subset 0.3.2 (.NET Runtime 7.0.2)
Required command was not provided.

Description:
  .NET Tool to copy a subset of files from a repository to a directory.

Usage:
  dotnet-subset [command] [options]

Options:
  --version       Show version information
  -?, -h, --help  Show help and usage information

Commands:
  restore <projectOrSolution>  Create a subset for the restore operation.
dmitriy-pisarevskiy commented 1 year ago

I have the same with update to net7 using buildx with arm64 as platform.

14 [linux/amd64 prepare-restore-files 2/6] RUN dotnet tool install --global --arch arm64 --no-cache dotnet-subset --version 0.3.2

0 1.963 Unhandled exception: System.AggregateException: One or more errors occurred. (The runtime identifier linux-arm64 is invalid. Valid runtime identifiers are: win-x64 win-arm64 osx-x64 osx-arm64.)

0 1.972 ---> Microsoft.DotNet.Cli.Utils.GracefulException: The runtime identifier linux-arm64 is invalid. Valid runtime identifiers are: win-x64 win-arm64 osx-x64 osx-arm64.

0 1.972 at Microsoft.DotNet.ShellShim.ShellShimTemplateFinder.ResolveAppHostSourceDirectoryAsync(String archOption, NuGetFramework targetFramework, Architecture arch)

0 1.972 --- End of inner exception stack trace ---

0 1.973 at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)

0 1.973 at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)

0 1.973 at Microsoft.DotNet.Tools.Tool.Install.ToolInstallGlobalOrToolPathCommand.Execute()

0 1.973 at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<b__0>d.MoveNext()

0 1.973 --- End of stack trace from previous location ---

0 1.973 at Microsoft.DotNet.Cli.Parser.<>c__DisplayClass17_0.<b__0>d.MoveNext()

0 1.974 --- End of stack trace from previous location ---

0 1.974 at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass11_0.<b__0>d.MoveNext()

0 1.974 --- End of stack trace from previous location ---

0 1.974 at System.CommandLine.CommandLineBuilderExtensions.<>c.<b__17_0>d.MoveNext()

0 1.974 --- End of stack trace from previous location ---

0 1.974 at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass15_0.<b__0>d.MoveNext()

0 1.975 --- End of stack trace from previous location ---

0 1.975 at System.CommandLine.CommandLineBuilderExtensions.<>c__DisplayClass7_0.<b__0>d.MoveNext()

dmitriy-pisarevskiy commented 1 year ago

ok, solved by downgrade to --version 0.3.1, seems something wrong with 0.3.2


#22 [linux/arm64 prepare-restore-files 2/5] RUN dotnet tool install --global --no-cache dotnet-subset --version 0.3.2
#22 53.13 You can invoke the tool using the following command: dotnet-subset
#22 53.13 Tool 'dotnet-subset' (version '0.3.2') was successfully installed.
#22 DONE 53.4s

#34 [linux/arm64 prepare-restore-files 3/5] WORKDIR /src
#34 DONE 0.0s

#35 [linux/arm64 prepare-restore-files 4/5] COPY . .
#35 DONE 0.3s

#36 [linux/arm64 prepare-restore-files 5/5] RUN dotnet subset restore "Services/Luna/Ruby.Services.Luna.Api/Ruby.Services.Luna.Api.csproj" --root-directory /src --output /src/restore_subset/
#36 15.69 dotnet-subset 0.3.2 (.NET Runtime 7.0.5)
#36 36.83 Unhandled exception: Microsoft.Build.Exceptions.InvalidProjectFileException: The expression "[Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKLocation('', '')" cannot be evaluated. Object reference not set to an instance of an object.  /usr/share/dotnet/sdk/7.0.203/Microsoft.Common.CurrentVersion.targets
#36 36.91    at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
#36 36.91    at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1,T2](IElementLocation elementLocation, String resourceName, T1 arg0, T2 arg1)
#36 36.91    at Microsoft.Build.Evaluation.Expander`2.Function`1.Execute(Object objectInstance, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation)
#36 36.91    at Microsoft.Build.Evaluation.Expander`2.PropertyExpander`1.ExpandPropertyBody(String propertyBody, Object propertyValue, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties, IFileSystem fileSystem)
#36 36.91    at Microsoft.Build.Evaluation.Expander`2.PropertyExpander`1.ExpandPropertiesLeaveTypedAndEscaped(String expression, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties, IFileSystem fileSystem, LoggingContext loggingContext)
#36 36.91    at Microsoft.Build.Evaluation.Expander`2.PropertyExpander`1.ExpandPropertiesLeaveEscaped(String expression, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties, IFileSystem fileSystem, LoggingContext loggingContext)
#36 36.91    at Microsoft.Build.Evaluation.Expander`2.ExpandIntoStringLeaveEscaped(String expression, ExpanderOptions options, IElementLocation elementLocation, LoggingContext loggingContext)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.EvaluatePropertyElement(ProjectPropertyElement propertyElement)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.EvaluatePropertyGroupElement(ProjectPropertyGroupElement propertyGroupElement)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.Evaluate()
#36 36.91    at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, Project project, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive)
#36 36.91    at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
#36 36.91    at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
#36 36.91    at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
#36 36.91    at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext, IDirectoryCacheFactory directoryCacheFactory)
#36 36.91    at Microsoft.Build.Evaluation.ProjectCollection.LoadProject(String fileName, IDictionary`2 globalProperties, String toolsVersion)
#36 36.91    at Nimbleways.Tools.Subset.RestoreSubset.VisitAllProjects(ProjectCollection projectCollection, String rootFolder, String projectPath, Dictionary`2 projects) in /home/runner/work/dotnet-subset/dotnet-subset/src/dotnet-subset/RestoreSubset.cs:line 108
#36 36.91    at Nimbleways.Tools.Subset.RestoreSubset.VisitAllProjects(ProjectCollection projectCollection, String rootFolder, String projectPath, Dictionary`2 projects) in /home/runner/work/dotnet-subset/dotnet-subset/src/dotnet-subset/RestoreSubset.cs:line 114
#36 36.91    at Nimbleways.Tools.Subset.RestoreSubset.Execute(String projectOrSolution, String rootFolder, String destinationFolder) in /home/runner/work/dotnet-subset/dotnet-subset/src/dotnet-subset/RestoreSubset.cs:line 19
#36 36.91    at Program.<>c.<<Main>$>b__0_0(FileInfo projectOrSolution, DirectoryInfo rootDirectory, DirectoryInfo outputDirectory) in /home/runner/work/dotnet-subset/dotnet-subset/src/dotnet-subset/Program.cs:line 38
#36 36.91    at System.CommandLine.Handler.<>c__DisplayClass4_0`3.<SetHandler>b__0(InvocationContext context)
#36 36.91    at System.CommandLine.Invocation.AnonymousCommandHandler.Invoke(InvocationContext context)
#36 36.91    at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext()
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext()
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__18_0>d.MoveNext()
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseDirective>b__0>d.MoveNext()
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__5_0>d.MoveNext()
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<<UseExceptionHandler>b__0>d.MoveNext()
#36 ERROR: process "/bin/sh -c dotnet subset restore \"Services/Luna/Ruby.Services.Luna.Api/Ruby.Services.Luna.Api.csproj\" --root-directory /src --output /src/restore_subset/" did not complete successfully: exit code: 1
------
 > [linux/arm64 prepare-restore-files 5/5] RUN dotnet subset restore "Services/Luna/Ruby.Services.Luna.Api/Ruby.Services.Luna.Api.csproj" --root-directory /src --output /src/restore_subset/:
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext()
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__18_0>d.MoveNext()
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseDirective>b__0>d.MoveNext()
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__5_0>d.MoveNext()
#36 36.91 --- End of stack trace from previous location ---
#36 36.91    at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<<UseExceptionHandler>b__0>d.MoveNext()
------
Dockerfile:13
--------------------
  11 |     WORKDIR /src
  12 |     COPY . .
  13 | >>> RUN dotnet subset restore "Services/Luna/Ruby.Services.Luna.Api/Ruby.Services.Luna.Api.csproj" --root-directory /src --output /src/restore_subset/
  14 |     
  15 |     FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build
--------------------
ERROR: failed to solve: process "/bin/sh -c dotnet subset restore \"Services/Luna/Ruby.Services.Luna.Api/Ruby.Services.Luna.Api.csproj\" --root-directory /src --output /src/restore_subset/" did not complete successfully: exit code: 1
Error: buildx failed with: ERROR: failed to solve: process "/bin/sh -c dotnet subset restore \"Services/Luna/Ruby.Services.Luna.Api/Ruby.Services.Luna.Api.csproj\" --root-directory /src --output /src/restore_subset/" did not complete successfully: exit code: 1
othmane-kinane-nw commented 1 year ago

Hello @dmitriy-pisarevskiy,

It seems like two different problems:

I have the same with update to net7 using buildx with arm64 as platform.

14 [linux/amd64 prepare-restore-files 2/6] RUN dotnet tool install --global --arch arm64 --no-cache dotnet-subset --version 0.3.2 #0 1.963 Unhandled exception: System.AggregateException: One or more errors occurred. (The runtime identifier linux-arm64 is invalid. Valid runtime identifiers are: win-x64 win-arm64 osx-x64 osx-arm64.)

It's a known issue using --arch arm64 on linux (link). The fix is to remove the argument, as you did in your second post.

36 [linux/arm64 prepare-restore-files 5/5] RUN dotnet subset restore "Services/Luna/Ruby.Services.Luna.Api/Ruby.Services.Luna.Api.csproj" --root-directory /src --output /src/restore_subset/

36 15.69 dotnet-subset 0.3.2 (.NET Runtime 7.0.5)

36 36.83 Unhandled exception: Microsoft.Build.Exceptions.InvalidProjectFileException: The expression "[Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKLocation('', '')" cannot be evaluated. Object reference not set to an instance of an object. /usr/share/dotnet/sdk/7.0.203/Microsoft.Common.CurrentVersion.targets

Are you having this error with 0.3.2, but not with 0.3.1 ? It's weird because I'm reviewing the changelog and there shouldn't be anything that would cause this error. I've created a new issue for this: https://github.com/nimbleways/dotnet-subset/issues/9