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

Conflicting SDK version results in unfriendly error message #787

Closed
am11 opened this issue Aug 28, 2020 · 2 comments
Closed

Conflicting SDK version results in unfriendly error message #787

am11 opened this issue Aug 28, 2020 · 2 comments

Comments

@am11
Copy link
Member

am11 commented Aug 28, 2020

When global.json has higher version of SDK than the one dotnet-format was built against, we get an unfreindly error:

Unable to locate MSBuild. Ensure the .NET SDK was installed with the official installer.

Steps to repro

# bash on macOS

# shallow clone dotnet/runtime's master branch
> git clone https://github.com/dotnet/runtime --single-branch --depth 1

# run dotnet-format out of the tree with --folder option
> dotnet-format runtime/src/libraries/System.Drawing.Common/src/System/Drawing/ --folder
  Unable to locate MSBuild. Ensure the .NET SDK was installed with the official installer.

# failed, return code
> echo $?
3

Workaround

# delete global.json and try again
> rm runtime/global.json
> dotnet-format runtime/src/libraries/System.Drawing.Common/src/System/Drawing/ --folder
> echo $?
0
# success!

Expected behavior

Either dotnet-format:

  • support this scenario with --folder option, by ignoring the SDK version mismatch and just format the code files. Maybe with a warning message, e.g. Some language features might not be supported. For optimal results, upgrade dotnet-format to latest version.
  • produce friendly message; something in between the lines of The SDK version in runtime/global.json is unsupported by dotnet-format.

Version info

> dotnet-format --version
v4.1.131201+82a5527cd93d66bffc885c0bb901499f5981db35

> dotnet --version
3.1.401
@JoeRobich
Copy link
Member

@am11 As of this PR - #760 - the 5.x builds no longer look for a MSBuild instance when using the --folder option.

When a global.json specifies a particular SDK, that SDK location will only be reported if it is installed. My assumption about what you ran into is that the version specified by the Runtime's global.json wasn't installed. Could you try running the Runtime's restore script to ensure the proper SDK is installed?

@am11
Copy link
Member Author

am11 commented Aug 29, 2020

Thanks a lot @JoeRobich! I tested with latest nightly and it has succeeded without the rm runtime/global.json workaround.

> dotnet tool install -g dotnet-format --version 5.0.142902 --add-source  https://dotnet.myget.org/F/format
> dotnet-format runtime/src/libraries/System.Drawing.Common/src/System/Drawing/ --folder
# success!

In my real case, I built the entire runtime repo (to test my branch) before issuing a PR, so the SDK (5.0 preview8) was installed in runtime's default location (under runtime/.dotnet). It was failing with v4.

With v5, even without restoring the runtime (i.e. fresh clone), it works with the --folder option.

Looking forward to the next official release. v5 has tons of improvements that I am fan of. ;)

@am11 am11 closed this as completed Aug 29, 2020
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

No branches or pull requests

2 participants