Skip to content

Conversation

@teo-tsirpanis
Copy link
Contributor

  • The NativeMethods class was updated to use the P/Invoke source generator, and [UnmanagedCallersOnly]. The changes made are in a similar vein to Use UnmanagedCallersOnly in AssemblyDependencyResolver. dotnet/runtime#119034.
  • The DotNetSdkLocationHelper class was updated to use APIs added in newer frameworks, like the regex source generator, or APIs to resolve symlinks. The latter also lets us remove the P/Invokes to libc.

@YuliiaKovalova
Copy link
Contributor

hi @teo-tsirpanis
please resolve the conflicts and I will review it

@teo-tsirpanis
Copy link
Contributor Author

@YuliiaKovalova conflicts resolved.

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, wait, something is wrong:

.\samples\BuilderApp\bin\Debug\net8.0\BuilderApp.exe .\MSBuildLocator.sln
Sample MSBuild Builder App 1.9.7+e4c2ece661.

Process terminated. Assertion failed.
   at Microsoft.Build.Locator.NativeMethods.hostfxr_resolve_sdk2_callback(hostfxr_resolve_sdk2_result_key_t key, Void* value) in S:\work\MSBuildLocator\src\MSBuildLocator\NativeMethods.cs:line 63
   at Microsoft.Build.Locator.NativeMethods.<hostfxr_resolve_sdk2>g____PInvoke|4_0(Void* __exe_dir_native, Void* __working_dir_native, hostfxr_resolve_sdk2_flags_t __flags_native,  __result_native)
   at Microsoft.Build.Locator.NativeMethods.<hostfxr_resolve_sdk2>g____PInvoke|4_0(Void* __exe_dir_native, Void* __working_dir_native, hostfxr_resolve_sdk2_flags_t __flags_native,  __result_native)
   at Microsoft.Build.Locator.NativeMethods.hostfxr_resolve_sdk2(String exe_dir, String working_dir, hostfxr_resolve_sdk2_flags_t flags,  result) in S:\work\MSBuildLocator\src\MSBuildLocator\obj\Debug\net8.0\Microsoft.Interop.LibraryImportGenerator\Microsoft.Interop.LibraryImportGenerator\LibraryImports.g.cs:line 19
   at Microsoft.Build.Locator.NativeMethods.hostfxr_resolve_sdk2(String exe_dir, String working_dir, hostfxr_resolve_sdk2_flags_t flags, String& resolved_sdk_dir, String& global_json_path) in S:\work\MSBuildLocator\src\MSBuildLocator\NativeMethods.cs:line 36
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.<GetInstances>g__GetSdkFromGlobalSettings|4_2(String workingDirectory) in S:\work\MSBuildLocator\src\MSBuildLocator\DotNetSdkLocationHelper.cs:line 153
   at Microsoft.Build.Locator.DotNetSdkLocationHelper.GetInstances(String workingDirectory, Boolean allowQueryAllRuntimes, Boolean allowAllDotnetLocations)+MoveNext() in S:\work\MSBuildLocator\src\MSBuildLocator\DotNetSdkLocationHelper.cs:line 82
   at Microsoft.Build.Locator.MSBuildLocator.GetInstances(VisualStudioInstanceQueryOptions options)+MoveNext() in S:\work\MSBuildLocator\src\MSBuildLocator\MSBuildLocator.cs:line 389
   at System.Linq.Enumerable.WhereEnumerableIterator`1.ToList()
   at BuilderApp.Program.Main(String[] args) in S:\work\MSBuildLocator\samples\BuilderApp\Program.cs:line 26

@rainersigwald
Copy link
Member

It is getting called twice, the first time with resolved_sdk_dir = 1, the second with 3. That appears to be newer than the docs describe

https://github.com/dotnet/runtime/blob/925205d06d82ce5e0d24e4e313fd66887fe89795/src/native/corehost/fxr/hostfxr.cpp#L225-L249

Maybe the assertions should be moved inside the switch @teo-tsirpanis?

@teo-tsirpanis
Copy link
Contributor Author

Removed assertions, as per the other native callback.

Copy link
Member

@rainersigwald rainersigwald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fantastic, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants