Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guide users of the MSBuild API towards loading MSBuild via MSBuild Locator instead of standard .NET Assembly Loading rules #10933

Open
baronfel opened this issue Nov 4, 2024 · 0 comments
Labels
Area: Debuggability Issues impacting the diagnosability of builds, including logging and clearer error messages. Cost:M Work that requires one engineer up to 2 weeks needs-design Requires discussion with the dev team before attempting a fix. Priority:1 Work that is critical for the release, but we could probably ship without triaged

Comments

@baronfel
Copy link
Member

baronfel commented Nov 4, 2024

Summary

We get a decent amount of issues and internal feedback from users attempting to use the MSBuild APIs to programmatically manipulate project files - either to read specific data, or to do what amounts to quasi-design-time builds, etc. In many cases these users have some quick success, but then break when trying to do something that's slightly harder than trivial. This is often because they are attempting to load MSBuild functionality from dlls placed alongside their projects. We should guide users of the MSBuild API to loading MSBuild dlls via MSBuild Locator, so that they have more success, and we have fewer issues to triage.

Background and Motivation

MSBuild requires more than just some dlls to work - it requires props, targets, and SDK resolvers (among others) and the normal PackageReference of Microsoft.Build doesn't satisfy all of those requirements. MSBuildLocator solves these problems for most users, and we have been directing users to use it for years. If we can get users out of the pit of failure when using the MSBuild APIs we should reduce our maintenance burden and increase user success rates.

Proposed Feature

Broadly, when an exception is thrown that would escape to the user, we should detect the context in which we are run and wrap the exception in a message guiding the user towards using MSBuildLocator if they are not already using MSBuildLocator.

Example Message (silly wording, etc):

Hey, we tried to load some critical data but it wasn't there. This is often because you're trying to load a bundled version of MSBuild, but you really should be using MSBuild Locator to bind to an existing MSBuild installation. See https://aka.ms/use-msbuild-locator for details.

Possible Check Locations:

  • Project constructors
  • Graph Node constructors
  • Basically anywhere that does Evaluation or Evaluation+Execution.

Broadly, a C# Exception Filter was what I was thinking:

try {
 ....
}
catch (Exception ex) when BuildEnvironmentHelper.Instance != whatever_means_msbuild_locator => // wrap ex in the message above

Alternative Designs

No response

@JanKrivanek JanKrivanek added Area: Debuggability Issues impacting the diagnosability of builds, including logging and clearer error messages. needs-design Requires discussion with the dev team before attempting a fix. triaged Priority:1 Work that is critical for the release, but we could probably ship without Cost:M Work that requires one engineer up to 2 weeks labels Nov 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Debuggability Issues impacting the diagnosability of builds, including logging and clearer error messages. Cost:M Work that requires one engineer up to 2 weeks needs-design Requires discussion with the dev team before attempting a fix. Priority:1 Work that is critical for the release, but we could probably ship without triaged
Projects
None yet
Development

No branches or pull requests

2 participants