Skip to content
This repository has been archived by the owner on May 17, 2024. It is now read-only.

try-convert fails when "Multiple installs of MSBuild" #429

Open
ATECoder opened this issue Feb 5, 2022 · 7 comments
Open

try-convert fails when "Multiple installs of MSBuild" #429

ATECoder opened this issue Feb 5, 2022 · 7 comments

Comments

@ATECoder
Copy link

ATECoder commented Feb 5, 2022

Using rev 0.9.232202 on Windows 11 VS 2022.

I am seeing the issues reported here: Dotnet project conversion try-convert fails when "Multiple installs of MSBuild"] on the VS 2022 build.

I am able to convert the same project on a Windows 10 system with both VS 2019 and 2022 versions installs and the same try-convert revision.

Upon adding the -m option, such as in
try-convert -tfm %1 --project %2 -m "C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\amd64"

I get the following exception:
Microsoft.Build.Exceptions.InvalidProjectFileException: SDK Resolver Failure: "The SDK resolver "Microsoft.DotNet.MSBuildSdkResolver" failed while attempting to resolve the SDK "Microsoft.NET.Sdk". Exception: "System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. Could not find or load a specific file. (0x80131621) File name: 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' ---> System.IO.FileLoadException: Could not load file or assembly 'Newtonsoft.Json, Version=13.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'. at System.Runtime.Loader.AssemblyLoadContext.LoadFromPath(IntPtr ptrNativeAssemblyLoadContext, String ilPath, String niPath, ObjectHandleOnStack retAssembly) at System.Runtime.Loader.AssemblyLoadContext.LoadFromAssemblyPath(String assemblyPath) at System.Reflection.Assembly.LoadFrom(String assemblyFile) at System.Reflection.Assembly.LoadFromResolveHandler(Object sender, ResolveEventArgs args) at System.Runtime.Loader.AssemblyLoadContext.InvokeResolveEvent(ResolveEventHandler eventHandler, RuntimeAssembly assembly, String name) at System.Runtime.Loader.AssemblyLoadContext.OnAssemblyResolve(RuntimeAssembly assembly, String assemblyFullName) at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadManifestReader.ReadWorkloadManifest(String manifestId, Stream manifestStream, Stream localizationStream, String informationalPath) at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.LoadManifestsFromProvider(IWorkloadManifestProvider manifestProvider) at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver..ctor(IWorkloadManifestProvider manifestProvider, ValueTuple2[] dotnetRootPaths, String[] currentRuntimeIdentifiers)
at Microsoft.NET.Sdk.WorkloadManifestReader.WorkloadResolver.Create(IWorkloadManifestProvider manifestProvider, String dotnetRootPath, String sdkVersion, String userProfileDir)
at Microsoft.NET.Sdk.WorkloadMSBuildSdkResolver.CachingWorkloadResolver.Resolve(String sdkReferenceName, String dotnetRootPath, String sdkVersion, String userProfileDir)
at Microsoft.DotNet.MSBuildSdkResolver.DotNetMSBuildSdkResolver.Resolve(SdkReference sdkReference, SdkResolverContext context, SdkResultFactory factory)
at Microsoft.Build.BackEnd.SdkResolution.SdkResolverService.ResolveSdk(Int32 submissionId, SdkReference sdk, LoggingContext loggingContext, ElementLocation sdkReferenceLocation, String solutionPath, String projectPath, Boolean interactive, Boolean isRunningInVisualStudio)"" C:\trash\core\core\isr.Data.Core.csproj
at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
at Microsoft.Build.Shared.ProjectErrorUtilities.VerifyThrowInvalidProject[T1](Boolean condition, String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, T1 arg0)
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.Evaluator4.Evaluate(IEvaluatorData4 data, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary1 environmentProperties, ILoggingService loggingService, IItemFactory2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCacheBase projectRootElementCache, BuildEventContext buildEventContext, ISdkResolverService sdkResolverService, Int32 submissionId, EvaluationContext evaluationContext, Boolean interactive)
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, EvaluationContext evaluationContext)
at Microsoft.Build.Evaluation.Project.ProjectImpl.ReevaluateIfNecessary(EvaluationContext evaluationContext)
at Microsoft.Build.Evaluation.Project.ProjectImpl.Initialize(IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext) at Microsoft.Build.Evaluation.Project..ctor(ProjectRootElement xml, IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings, EvaluationContext evaluationContext)
at Microsoft.Build.Evaluation.Project..ctor(ProjectRootElement xml, IDictionary2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings) at Microsoft.Build.Evaluation.Project..ctor(ProjectRootElement xml, IDictionary2 globalProperties, String toolsVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
at Microsoft.Build.Evaluation.Project..ctor(ProjectRootElement xml, IDictionary2 globalProperties, String toolsVersion, ProjectCollection projectCollection) at MSBuild.Abstractions.UnconfiguredProject.LoadProjects(ProjectCollection collection, ProjectRootElement rootElement) in /_/src/MSBuild.Abstractions/UnconfiguredProject.cs:line 40 at MSBuild.Abstractions.MSBuildConversionWorkspace.TryCreateSdkBaselineProject(String projectFilePath, IProject project, IProjectRootElement root, ImmutableDictionary2 configurations, String tfm, Boolean keepCurrentTFMs, Nullable1& baselineProject) in /_/src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs:line 196 at MSBuild.Abstractions.MSBuildConversionWorkspace..ctor(ImmutableArray1 paths, Boolean noBackup, String tfm, Boolean keepCurrentTFMs, Boolean forceWeb) in //src/MSBuild.Abstractions/MSBuildConversionWorkspace.cs:line 55
at MSBuild.Abstractions.MSBuildConversionWorkspaceLoader.LoadWorkspace(String path, Boolean noBackup, String tfm, Boolean keepCurrentTFMs, Boolean forceWeb) in /
/src/MSBuild.Abstractions/MSBuildConversionWorkspaceLoader.cs:line 45
at MSBuild.Conversion.Program.Run(String project, String workspace, String msbuildPath, String tfm, Boolean forceWebConversion, Boolean preview, Boolean diffOnly, Boolean noBackup, Boolean keepCurrentTfms, Boolean update, Boolean mauiConversion) in /_/src/try-convert/Program.cs:line 133
`

@bwilliams1
Copy link

I ran into this issue as well. Running try-convert within a "Developer Command Prompt for VS 2019" seemed to work around it.

@twsouthwick
Copy link
Member

Interesting. Can you run dotnet --list-sdks and paste the output?

@bwilliams1
Copy link

Interesting. Can you run dotnet --list-sdks and paste the output?

dotnet --list-sdks
5.0.403 [C:\Program Files\dotnet\sdk]
6.0.100 [C:\Program Files\dotnet\sdk]
6.0.101 [C:\Program Files\dotnet\sdk]

I did notice it works on a vanilla "cmd.exe" but reports the error on "Developer Command Prompt for VS 2022". all 3 command prompt versions report the same for "dotnet --list-sdks"

@twsouthwick
Copy link
Member

Ah - in general, both try-convert and upgrade-assistant are expected to run in a terminal without the environment variables set by the developer command prompt. They set those variables internally and if they're already set it may conflict with resolution done by the tool.

@ATECoder
Copy link
Author

ATECoder commented Mar 8, 2022

This is what I have (on the Visual Studio 2022 only VM):

6.0.200 [C:\Program Files\dotnet\sdk]

@modz2014
Copy link

i get the same issue as well

@aserie
Copy link

aserie commented Aug 30, 2022

I think the tool could have some better logging if it couldn't find MSBuild.exe. Looks like there is a check here if just one instance of MSBuild was found and shows the Multiple installs of MSBuild selector in all other cases (including the zero case).

try-convert uses MSBuildLocator to attempt to find MSBuild.exe on the machine to use. From my past experience, if you have ONLY a newer version of .NET SDK installed on your machine than what the tool is targeting, MSBuildLocator won't locate your newer SDK.

At the time of writing this, the released version of try-convert v0.9.232202 is targeting .NET5. Ensure you have the .NET5 x64 SDK installed on your machine and attempt to run try-convert again. You can check what installed versions you have by running dotnet --list-sdks.

Edit:
Looking a bit closer at MSBuildLocator, skipping SDKs that are newer than the apps targeted runtime is desired behavior.
microsoft/MSBuildLocator#92

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants