GithubHelp home page GithubHelp logo

3f / hmsbuild Goto Github PK

View Code? Open in Web Editor NEW
19.0 7.0 5.0 215 KB

.bat scripts with full Package Manager inside for searching and wrapping MSBuild tools. All Visual Studio and .NET Framework versions

License: MIT License

Batchfile 100.00%
msbuild vswhere visual-studio build portable embeddable tools getnutool distribution ci

hmsbuild's Introduction

.bat scripts with full Package Manager inside for searching and wrapping MSBuild tools. All Visual Studio and .NET Framework versions.

You do NOT need powershell or dotnet-cli or local vswhere.exe [?]

Copyright (c) 2017-2024  Denis Kuzmin <x-3F@outlook.com> github/3F

「 ❤ 」 License Build status release GetNuTool

Build history

hMSBuild -only-path -no-vs -notamd64 -no-less-4
hMSBuild -debug ~x ~c Release
hMSBuild -GetNuTool "Conari;regXwild;Fnv1a128"
hMSBuild -GetNuTool vsSolutionBuildEvent/1.16.0:../SDK & SDK\GUI
hMSBuild -cs -no-less-15 /t:Rebuild

Download all editions: Full, Minified, ...

Official Direct Links:

  • (Windows) Latest stable compiled batch-script [ hMSBuild.bat ] https://3F.github.io/hMSBuild/releases/latest/

Why hMSBuild

because you need easy access to msbuild tools and more...

Based on GetNuTool and back in those days it was part of it like a small msbuild-helper inside. But finally it was extracted into a new independent project after major changes from MS ecosystem with their products.

Today's hMSBuild provides the most flexible way to access and preparing msbuild tools in different environments. You just specify what you need ... and hMSBuild prepares it for you.

{Screencast - hMSBuild in action. Demo via RunIlAsm error}

Key Features

  • Single *.bat file, no less, no more.
  • Manage all versions, including before install-API/2017+
  • Visual Studio versions support: VS2022+, VS2019, VS2017, VS2015, VS2013, VS2012, VS2010
  • .NET Framework versions support: 4.0 (2010), 3.5, 2.0
  • Lightweight and text-based, about ~8 KB + ~11 KB
  • Does not require powershell or dotnet-cli or even local vswhere.exe [?]
  • Support hot updating / custom vswhere at any request for the most modern environments.
  • Provides some useful aliases.
  • Full package manager inside .bat to Create or Distribute using basic shell scripts;
  • Request to the server only if the package is not installed.
  • Support packages.config (+extra: output, sha1 if used unsecured channels ~windows xp).
  • Easy integration into any scripts such as pure batch-script netfx4sdk, DllExport

hMSBuild's algorithm

The basic process is to provide the most suitable instance by explicitly eliminating unnecessary ones.

2.0+

  • Versions:

    • VS2022, ..., VS2017 ➟ VS2015, VS2013, ... ➟ .netfx
  • Instance Architecture (configure via -notamd64 key):

    • x64 ➟ x32
  • Extra restrictions via -no-less-4 (Windows XP+), -no-less-15 (install-API/2017+)

  • Priorities (configure via -priority, -vc, cs, -stable, ... keys). Specific workload components in more priority than pre-release products. See Issue #8

    1. Stable releases with selected workload components (C++ etc) ➟ Same via beta releases if allowed.
    2. Stable releases with any available components ➟ Same via beta releases if allowed.

Syntax

Keys to hMSBuild are optional. You can still command like it is official msbuild.exe (MSBuild Tools).

hMSBuild [keys to hMSBuild] [keys to msbuild.exe]

For example,

  • The Clean target in current directory: hmsbuild /t:Clean
  • Set property Configuration and minimal verbosity: hmsbuild /p:Configuration=Debug /v:m
    • via hMSBuild it can also be like: hmsbuild ~x ~c Debug

In order to use package manager,

hMSBuild -GetNuTool keys to it ...

  • Get latest packages: hmsbuild -GetNuTool "Conari;regXwild;Fnv1a128"
  • Activate GUI script editor: hMSBuild -GetNuTool vsSolutionBuildEvent/1.16.0:../SDK & SDK\GUI
  • Create new package: hmsbuild -GetNuTool /t:pack /p:ngin=packages/Fnv1a128

-... or /...

MSBuild Tools supports both key format /... and -...; hMSBuild, in turn, can override some of -...; in this case you need to use /... for example,

  • /version will be addressed to found MSBuild;
  • -version will be addressed to hMSBuild;

"..."

Any value for specific key must be protected inside "..." if contains either whitespaces or delimiters like ; For example:

hmsbuild ~p "Any CPU"

-help

For the most up-to-date information, use hMSBuild -h

hMSBuild 2.4.0
Copyright (c) 2017-2024  Denis Kuzmin <[email protected]> github/3F
Copyright (c) hMSBuild contributors https://github.com/3F/hMSBuild

Under the MIT License https://github.com/3F/hMSBuild

Syntax: hMSBuild [keys to hMSBuild] [keys to MSBuild.exe or GetNuTool]

Keys
~~~~
 -no-vs        - Disable searching from Visual Studio.
 -no-netfx     - Disable searching from .NET Framework.
 -no-vswhere   - Do not search via vswhere.
 -no-less-15   - Do not include versions less than 15.0 (install-API/2017+)
 -no-less-4    - Do not include versions less than 4.0 (Windows XP+)

 -priority {IDs} - 15+ Non-strict components preference: C++ etc.
                   Separated by space "a b c" https://aka.ms/vs/workloads

 -vswhere {v}
  * 2.6.7 ...
  * latest - To get latest remote vswhere.exe
  * local  - To use only local
            (.bat;.exe /or from +15.2.26418.1 VS-build)

 -no-cache         - Do not cache vswhere for this request.
 -reset-cache      - To reset all cached vswhere versions before processing.
 -cs               - Adds to -priority C# / VB Roslyn compilers.
 -vc               - Adds to -priority VC++ toolset.
 ~c {name}         - Alias to p:Configuration={name}
 ~p {name}         - Alias to p:Platform={name}
 ~x                - Alias to m:NUMBER_OF_PROCESSORS-1 v:m
 -notamd64         - To use 32bit version of found msbuild.exe if it's possible.
 -stable           - It will ignore possible beta releases in last attempts.
 -eng              - Try to use english language for all build messages.
 -GetNuTool {args} - Access to GetNuTool core. https://github.com/3F/GetNuTool
 -only-path        - Only display fullpath to found MSBuild.
 -force            - Aggressive behavior for -priority, -notamd64, etc.
 -vsw-as "args..." - Reassign default commands to vswhere if used.
 -debug            - To show additional information from hMSBuild
 -version          - Display version of hMSBuild.
 -help             - Display this help. Aliases: -? -h

Integration with scripts

batch (.bat, .cmd)

hMSBuild is a pure batch script. Therefore, you can easily combine this even inside other batch scripts. Or invoke this externally, there's nothing special:

set msbuild=hMSBuild -notamd64 ~c Release
...
%msbuild% Conari.sln /t:Rebuild
for /F "tokens=*" %%i in ('hMSBuild -only-path -notamd64') do set msbuild="%%i"
...
%msbuild% /version
hmsbuild -cs -no-less-15 ~c Debug ~x || goto failed

More actual examples can be found in tests/ folder.

Note: for some cases, if you know what you're doing, you can also configure __p_call flag to eliminate the difference for the call-type invoking hMSBuild.bat

set __p_call=1

Build & Tests

build and tests was based on batch and vssbe scripts. You don't need to do anything else, just build and test it

build & tests

Build and Use from source

git clone https://github.com/3F/hMSBuild.git src
cd src & build & bin\Release\hMSBuild -help

.sha1 official distribution

hMSBuild releases are now accompanied by a .sha1 file in the official distribution; At the same time, commits from which releases are published are signed with the committer's verified signature (GPG).

Make sure you are using official, unmodified, safe versions.

Note: .sha1 file is a text list of published files with checksums in the format:

40-hexadecimal-digits <space> file

eead8f5c1fdff2abd4da7d799fbbe694d392c792 path\file
...

Contributing

hMSBuild is waiting for your awesome contributions!

hmsbuild's People

Contributors

3f avatar gerhardol avatar odalet-addup avatar uli-weltersbach avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

hmsbuild's Issues

1.2.x Possible False activated `-vswhere-version` key. (400) Bad Request, etc

Found this today before new DllExport release.

For example:
https://ci.appveyor.com/project/3Fs/dllexport/build/build-102

9:03:09 PM.4121 [INFO]: Result of the command: `selected new vswhere version: "MvsSln.sln"`
9:03:11 PM.4982 [INFO]: stderr: received '55'
9:03:11 PM.4982 [WARN]: The command has been executed with error: `The remote server returned an error: (400) Bad Request.`
9:03:11 PM.5672 [INFO]: stderr: received '42'
9:03:11 PM.5672 [WARN]: The command has been executed with error: `The system cannot find the path specified.`
9:03:11 PM.5792 [INFO]: stdout: received '75'
9:03:11 PM.5792 [INFO]: Result of the command: `hMSBuild: "\MSBuild\C:\projects\dllexport\tools\vswhere.0\Bin\MSBuild.exe" `
9:03:11 PM.5792 [INFO]: stderr: received '66'
9:03:11 PM.5792 [WARN]: The command has been executed with error: `The filename, directory name, or volume label syntax is incorrect.`
9:03:11 PM.5792 [INFO]: stderr: received '15'
9:03:11 PM.5792 [WARN]: The command has been executed with error: ` Build failed. `
9:03:11 PM.5792 [INFO]: [Pre] finished SBE: Custom build for dependencies ...

And this is why:

:: 1.2.2 minified version
if "!an:~0,16!"=="-vswhereVersion " set as=1
if "!an:~0,17!"=="-vswhere-version " set as=1
if defined as (            <<<<<<<<<<<<^^^^^^^ 
set "as="
call :be %1 & shift
set aj=%2
echo selected new vswhere version: !aj!
call :be %2 & shift
)

the as can be defined outside current env but we have no set "as=" before this block.

Affects for any editions from 1.2.x. However, full version less prone to errors because of more long name.

You can try to avoid this error via local scope, for example, for minified and the light edition it can be like:

setlocal & (set "as=" & cd MvsSln & build PublicRelease) & endlocal

Visual Studio 2017 Update 3 / MSBuild 15.3

Microsoft decided to put v15.3 of MSBuild.exe in <VS2017 install dir>\MSBuild\15.0\Bin, not <VS2017 install dir>\MSBuild\15.3\Bin.

MSBuild.exe version

This means that the vsver variable is set incorrectly after updating to Visual Studio 2017 Update 3.
We've fixed it locally by changing line 323 of hMSBuild.bat (v1.2.1) from set vsver=%%a.%%b to set vsver=%%a.0.

Thanks for making your script available to the public, by the way :)

Find MSBuild when only Build Tools are installed

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

Non-zero exit code when compilation fails

I love your script, but I always end up modifying line 231 (v1.2.1) to return %ERRORLEVEL% instead of zero, so that hMSBuild.bat returns a non-zero exit code when MSBuild.exe fails.

Is there any reason why you decided to always return zero, even when MSBuild.exe encounters an error?

Control of the priority for MSBuild versions

Mentioned by @odalet from #13 (comment)

If I simply run hmsbuild, the returned version of MSBuild is 15.8 (btw I don't know why the more recent 16.0 one is not picked...)

So what's going on if we're talking about VS2017+

This is so, because of this:

hMSBuild/frontend.bat

Lines 469 to 471 in 4b368c9

if defined vspath if defined vsver (
call :vswmsb vspath vsver msbf
if defined msbf goto _vswbinReturn

But in general, it depends on installation order in your machine and current ISetupConfiguration2.EnumAllInstances / IEnumSetupInstances.Next implementation. Which may sort the available products by something.

vswhere will just enumerate it 'as is' (see installation API):

just installed 2017 & 2019 on clean VM:

:: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community "
:: "15.9.28307.770 "
:: "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community "
:: "16.1.29102.190 "

that is:

instanceId: 2d0578b0
installDate: 7/19/2019 5:49:56 AM
installationName: VisualStudio/15.9.14+28307.770
installationPath: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community
installationVersion: 15.9.28307.770
productId: Microsoft.VisualStudio.Product.Community
productPath: C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\devenv.exe
state: 4294967295
isComplete: 1
isLaunchable: 1
isPrerelease: 0
isRebootRequired: 0
displayName: Visual Studio Community 2017
description: Free, fully-featured IDE for students, open-source and individual developers
channelId: VisualStudio.15.Release
channelUri: https://aka.ms/vs/15/release/channel
enginePath: C:\Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service
releaseNotes: https://go.microsoft.com/fwlink/?LinkId=660692#15.9.14
thirdPartyNotices: https://go.microsoft.com/fwlink/?LinkId=660708
updateDate: 2019-07-19T12:49:56.4989618Z
catalog_buildBranch: d15.9
catalog_buildVersion: 15.9.28307.770
catalog_id: VisualStudio/15.9.14+28307.770
catalog_localBuild: build-lab
catalog_manifestName: VisualStudio
catalog_manifestType: installer
catalog_productDisplayVersion: 15.9.14
catalog_productLine: Dev15
catalog_productLineVersion: 2017
catalog_productMilestone: RTW
catalog_productMilestoneIsPreRelease: False
catalog_productName: Visual Studio
catalog_productPatchVersion: 14
catalog_productPreReleaseMilestoneSuffix: 1.0
catalog_productRelease: RTW
catalog_productSemanticVersion: 15.9.14+28307.770
catalog_requiredEngineVersion: 1.18.1049.33485
properties_campaignId: 112003091.1563535912
properties_channelManifestId: VisualStudio.15.Release/15.9.14+28307.770
properties_nickname:
properties_setupEngineFilePath: C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installershell.exe

instanceId: bcc9b5bf
installDate: 7/19/2019 5:00:06 AM
installationName: VisualStudio/16.1.6+29102.190
installationPath: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community
installationVersion: 16.1.29102.190
productId: Microsoft.VisualStudio.Product.Community
productPath: C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\devenv.exe
state: 4294967295
isComplete: 1
isLaunchable: 1
isPrerelease: 0
isRebootRequired: 0
displayName: Visual Studio Community 2019
description: Free, fully-featured IDE for students, open-source and individual developers
channelId: VisualStudio.16.Release
channelUri: https://aka.ms/vs/16/release/channel
enginePath: C:\Program Files (x86)\Microsoft Visual Studio\Installer\resources\app\ServiceHub\Services\Microsoft.VisualStudio.Setup.Service
releaseNotes: https://go.microsoft.com/fwlink/?LinkId=660893#16.1.6
thirdPartyNotices: https://go.microsoft.com/fwlink/?LinkId=660909
updateDate: 2019-07-19T12:00:06.2984029Z
catalog_buildBranch: d16.1
catalog_buildVersion: 16.1.29102.190
catalog_id: VisualStudio/16.1.6+29102.190
catalog_localBuild: build-lab
catalog_manifestName: VisualStudio
catalog_manifestType: installer
catalog_productDisplayVersion: 16.1.6
catalog_productLine: Dev16
catalog_productLineVersion: 2019
catalog_productMilestone: RTW
catalog_productMilestoneIsPreRelease: False
catalog_productName: Visual Studio
catalog_productPatchVersion: 6
catalog_productPreReleaseMilestoneSuffix: 1.0
catalog_productSemanticVersion: 16.1.6+29102.190
catalog_requiredEngineVersion: 2.1.3096.46871
properties_campaignId: 112003091.1563535912
properties_channelManifestId: VisualStudio.16.Release/16.1.6+29102.190
properties_nickname: 2
properties_setupEngineFilePath: C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installershell.exe

legacy products: 10, 11, 12, 14

Don't forget about legacy products. The part for this here:

(from newer to older versions:)

hMSBuild/frontend.bat

Lines 548 to 577 in 4b368c9

:msbvsold {out:toolset}
call :dbgprint "Searching from Visual Studio - 2015, 2013, ..."
for %%v in (14.0, 12.0) do (
call :rtools %%v Y & if defined Y (
set %1=!Y!
exit /B 0
)
)
call :dbgprint "-vs: not found"
set "%1="
exit /B 0
:: :msbvsold
:: - - -
:: Tools from .NET Framework - .net 4.0, ...
:msbnetf {out:toolset}
call :dbgprint "Searching from .NET Framework - .NET 4.0, ..."
for %%v in (4.0, 3.5, 2.0) do (
call :rtools %%v Y & if defined Y (
set %1=!Y!
exit /B 0
)
)
call :dbgprint "-netfx: not found"
set "%1="
exit /B 0
:: :msbnetf

The Question is

Some additional processing from our side is possible for both cases above. But I don't think that's important for hMSBuild project because of minimal filter etc.

However, please comment and/or open PR for relevant changes.

Add filter or priorities for searching MSBuild together with specific workload components

We need to provide some priorities in search result when user's machine contains 2 or more VS2017+ installed instances with different components.

The basic example is for C++ projects and several versions of installed VS2017:

  • The one of these contains only - [.NET desktop development]
  • Other, only - [Desktop development with C++]

~

C:\Program Files (x86)\VS\2017\Professional\MSbuild\
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\

Current version may return path for what is not needed:

error MSB4019: 
The imported project "C:\Program Files (x86)\VS\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Default.props" was not found. 
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

So we need to specify some priorities for searching via IDs.

The priority means only trying with these in first attempts. But, I think also about -force key for more strong behaviour.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.