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

Find MSBuild when only Build Tools are installed #12

Closed
odalet opened this issue Jul 8, 2019 · 3 comments
Closed

Find MSBuild when only Build Tools are installed #12

odalet opened this issue Jul 8, 2019 · 3 comments

Comments

@odalet
Copy link

odalet commented Jul 8, 2019

I installed a new machine only with VS2019 Build Tools and hmsbuild only finds C:\Windows\Microsoft.NET\Framework64\v4.0.30319\\MSBuild.exe. Well that's not good because my build really needs a recent MSBuild.

After having a look at the un-minified source code here + vswhere conditions for detecting Build Tools (it does not by default, which, imo, is a pity...), I hacked directly in the minified hmsbuild and added the -products * in the call to vswhere. And bam, here my brand new MSBuild from VS2019 appears...

Could you add this option? This would be really helpful for CI machines. Thanks!

PS: Attached is my modified hMSBuild. The interesting line is #292
hMSBuild.bat.txt

@3F
Copy link
Owner

3F commented Jul 8, 2019

Thanks for the report!

Right, the default values of -products key just points to the following products: Community, Professional, Enterprise. While Microsoft.VisualStudio.Product.BuildTools can be installed separately.

I'm not sure about -products * because it also includes:

  • Microsoft.VisualStudio.Product.TestAgent
  • Microsoft.VisualStudio.Product.TestController
  • Microsoft.VisualStudio.Product.TeamExplorer
  • ... any other future product

https://aka.ms/vs/workloads

But anyway, the mentioned BuildTools is important for our hMSBuild to be searched by default.

Here's src of this part: https://github.com/3F/hMSBuild/blob/master/frontend.bat
You can open WIP PR while we're thinking about other products and/or additional options for this.

Cc: @gerhardol

@odalet
Copy link
Author

odalet commented Jul 9, 2019

OK, so I used -products * because this is what the vswhere team suggested in issue microsoft/vswhere#61. In this same issue, they refer to this doc: https://github.com/Microsoft/vswhere/wiki/Find-MSBuild and specifically to the last paragraph... However, in its current state, the mention to use -products * is not consistent with the examples above (use of a newer -find option); going back in the history of this page, we can see usage examples of -products *.

Imo, vswhere should support VS Build Tools the same way it supports other editions; however, judging by the comments in various issues, it seems they won't do that. Anyway (and this goes for the -find option as well), because hmsbuild needs work with old releases of VS/vswhere, I suppose it should stick with existing detection methods. By the way, microsoft/vswhere#61 explains the -products * switch works from version 1.0.40 of vswhere (this was in March of 2017) - I don't know if this is something hmsbuild should cope with...

If you want to limit the range of workloads searched for msbuild, we'll have to pass the whole list of workloads we want to support; something along this line:

vswhere.exe -products Microsoft.VisualStudio.Product.BuildTools Microsoft.VisualStudio.Product.Community Microsoft.VisualStudio.Product.Professional Microsoft.VisualStudio.Product.Enterprise

I ensured this snippet indeed found something both on my French Windows 10 workstation (with VS2017 + VS2019 Enterprise) and on my CI Server (English Windows 2019) with only VS2019 Build Tools (hence I'm rather confident about the space being a work-across-cultures separator)

In the meantime, I'll provide you with the PR (simply adding -products *); up to you to decide whether you want to explicit the searched workloads.

Any way, thanks for this cool tool!

@3F
Copy link
Owner

3F commented Jul 9, 2019

I don't know if this is something hmsbuild should cope with...

hMSBuild was based on GetNuTool so you can even use specific version of vswhere via -vsw-version in various CI env.

About -products *, I think we will do as follows:

In 2.0 I implemented an -vsw-priority key for components preference. Therefore, we still can control flexibly our workloads without additions or even through specific set for -products key.

#8 (comment)

hMSBuild -vsw-priority ...

Can someone else also check this scenario when -products * (#13) ?

thanks for this cool tool!

I'm glad that's really helpful tool. We also use it a lot :)

3F added a commit that referenced this issue Jul 19, 2019
@3F 3F closed this as completed Jul 19, 2019
3F added a commit that referenced this issue Jul 20, 2019
* FIXED: Fixed searching from MS BuildTools products. Issue #12 (Thanks @odalet).

* CHANGED: [VS2017+] hMSBuild will search now in ANY available products. PR #13 (Thanks @odalet).

* NOTE: In addition to changes above, please use `-vsw-priority` and `-force` keys to use only what is needed.
        Issues: #8, #14.
3F added a commit that referenced this issue Jan 29, 2020
* NEW: Implemented `-vsw-as "args..."`
       Reassigns default commands to vswhere if used.

       For example:
       ```
       hMSBuild -only-path -vsw-as "-products Microsoft.VisualStudio.Product.BuildTools"
       ```
       Related Issues: #12, #14, #8,

* CHANGED: VS2017+. Using the most modern instance by default.
           You can also specify `-vsw-priority` and `-force` keys to use only what is needed.
           Related Issues: #14, #8.

* CHANGED: Updated wswhere to 2.8.4 by default.

* CHANGED: Updated GetNuTool 1.8
           https://github.com/3F/GetNuTool/releases/tag/1.8

           Most important fix for hMSBuild:
           "The remote server returned an error: (407) Proxy Authentication Required."
           Related issue: 3F/DllExport#133

* NOTE: An compiled.full version now will be distributed together with official hMSBuild releases.
           https://twitter.com/GitHub3F/status/1218224792970715136
           (zip packages) https://github.com/3F/hMSBuild/releases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants