RicoSuter / DNT

DNT (DotNetTools): Command line tools to manage .NET projects and solutions.
MIT License
416 stars 63 forks source link

.NET 7 Preview version causing DNT to fail (we had the same problem when we moved from 5->6) #121

Open ShaharPrishMSFT opened 2 years ago

ShaharPrishMSFT commented 2 years ago

When trying to run the switch-to-projects command, I get an error. The only thing that changed AFAIK is the build of VS 2022 preview, which defaults to .net 7 (the projects are all .net 6 projects though).

This used to happen at a similar time when we moved from 5 to 6. (The error is very long and is here: https://pastebin.pl/view/7e005592)

The beginning of the exception:

The project 'C:\src\wicd\TVM.ComputeService.2\ConfigGen\ConfigGeneration.ValueFileBuilder\ConfigGeneration.ValueFileBuilder.csproj' could not be loaded: System.InvalidOperationException: Not a project: C:\src\wicd\TVM.ComputeService.2\ConfigGen\ConfigGeneration.ValueFileBuilder\ConfigGeneration.ValueFileBuilder.csproj ---> Microsoft.Build.Exceptions.InvalidProjectFileException: SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified. File name: 'System.Runtime, Version=7.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.WorkloadSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext resolverContext, SdkResultFactory factory) at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.TryResolveSdkUsingSpecifiedResolvers(IList1 resolvers, Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio, SdkResult& sdkResult)"" C:\src\wicd\TVM.ComputeService.2\ConfigGen\ConfigGeneration.ValueFileBuilder\ConfigGeneration.ValueFileBuilder.csproj at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args) at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject[T1](IElementLocation elementLocation, String resourceName, T1 arg0) at Microsoft.Build.Evaluation.Evaluator4.ExpandAndLoadImportsFromUnescapedImportExpressionConditioned(String directoryOfImportingFile, ProjectImportElement importElement, List1& projects, SdkResult& sdkResult, Boolean throwOnFileNotExistsError) at Microsoft.Build.Evaluation.Evaluator4.ExpandAndLoadImports(String directoryOfImportingFile, ProjectImportElement importElement, SdkResult& sdkResult) at Microsoft.Build.Evaluation.Evaluator4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement) at Microsoft.Build.Evaluation.Evaluator4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport) at Microsoft.Build.Evaluation.Evaluator4.Evaluate() at Microsoft.Build.Evaluation.Project.ProjectImpl.Reevaluate(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation,

ShaharPrishMSFT commented 2 years ago

I have a PR that fixes this:

https://github.com/RicoSuter/DNT/pull/122

bkromhout commented 1 year ago

Hi, is there any possible way to work around this issue while we're waiting for the PR to be merged to fix the issue? Or would it require downgrading Visual Studio? I'm not running a preview version, but I suspect that VS 2022 17.4.0, which I just updated to today, causes the same issue.

ShaharPrishMSFT commented 1 year ago

@bkromhout : I dont know of a workaround. I currently use the one I compiled for the PR when I need to run. Waiting for it to get merged :(

Leon99 commented 1 year ago

Same here, dnt throws on start after upgrading VS 2022 to 17.4.0. @RicoSuter any chances you could approve the PR?

poxet commented 1 year ago

I pulled down #122 and built it locally. Now I'm running C:\dev\DNT\src\Dnt\bin\Debug\net7.0\dnt.exe switch-to-projects switcher.json. It works perfectly. Will be great when this is merged so we can use the real dotnet tool install.

RicoSuter commented 1 year ago

Should be fixed in v1.8.1

RicoSuter commented 1 year ago

DNT needs to be upgraded to explicitly support the new .NET runtime and that's why it also initially failed for 5->6.

bkromhout commented 1 year ago

@RicoSuter, any estimate on when 1.8.1 will be available on Nuget? Seems like the CI build is failing currently

RicoSuter commented 1 year ago

Works for me now...

bkromhout commented 1 year ago

Oh, my apologies, upon closer inspection it looks like I was having an unrelated error due to one of our private nuget feeds. Thanks!

fabsulous commented 1 year ago

I am curious whether there is a way to prevent that this will be failing again when the next update is happening. Is it possible to only target something really low, maybe even .NET Standard, and let DOTNET_ROLL_FORWARD take care of the rest?

RicoSuter commented 1 year ago

I think because it's a global tool it cannot be .net std.