Skip to content
/ hMSBuild Public

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

License

Notifications You must be signed in to change notification settings

3F/hMSBuild

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Does NOT require powershell or dotnet-cli or even local vswhere.exe [?]. Powered by GetNuTool

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

「 ❤ 」 License Build status release

gnt~hMSBuild | gnt*hMSBuild | Self updating: hMSBuild -GetNuTool ~hMSBuild/2.5

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

Download all editions: Full, Minified, ...

Direct Links to the latest stable:

  • (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: VS2026+, 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:

    • VS2026+, 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.1:../SDK & SDK\GUI
  • Create new package: hmsbuild -GetNuTool /t:pack /p:ngin=packages/Fnv1a128
  • Use X mode in modern core: hmsbuild -GetNuTool *DllExport ([?] * install and run; + just install, ~ touch mode)

Key format -... 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"

LF / CRLF

Starting with 2.5, hMSBuild.bat edition now fully supports LF and uses this by default instead of CRLF.

It means .gitattributes control for CRLF in hMSBuild.bat is not necessary anymore in cases when core.autocrlf=input etc. See related: #2

However, this will not affect users who used the full edition hMSBuild.full.bat (related #11) which is still not protected due to incorrect shiftings in cmd processor when switching to LF.

-help

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

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

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         - Prefer 32-bit instead of 64-bit MSBuild.exe.
 -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 (built-in) https://github.com/3F/GetNuTool
                     hMSBuild -GetNuTool -help
                     hMSBuild -GetNuTool ~/p:use=documentation

 -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 fallback

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

API

2.5+

:: initialize arguments
:inita {in:vname} {in:arguments} {out:index}
    ::   (1) - Input variable name.
    ::  &(2) - Input arguments via a variable.
    :: *&(3) - Returns the reached index (maximum) via a variable.
    :: !!0
:: evaluate argument
:eva {in:unevaluated} {out:evaluated} {in:option}
    ::  &(1) - Input via a variable. Use ` to apply " quotes inside "..." if [3]==1.
    :: *&(2) - Evaluated output via a variable.
    ::   [3] - Option to enable support for extra quotes. Values: 1 == ` as "
    :: !!0

Usage for example, DllExport.bat:

:inita

:: process arguments through hMSBuild
call :inita arg esc amax
...
set key=!arg[%idx%]!
...
:continue
set /a "idx+=1" & if %idx% LSS !amax! goto loopargs

:eva

set /a "idx+=1" & call :eval arg[!idx!] v
...

:eval
    call :eva %*
exit /B

Full hMSBuild edition

In case you need the full edition (related #11)

Access using built-in core:

hMSBuild -GetNuTool ~hMSBuild /p:use=full

or:

gnt ~hMSBuild /p:use=full

note: hMSBuild -GetNuTool ~ (hMSBuild -GetNuTool ~& gnt ...) or visit https://github.com/3F/GetNuTool

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

e9e533b0da8e5546eff821a40fbf7ca20ab9cf7e path\file
...

hMSBuild.bat self validation

It is important to note the following: this is not a specialized protection of hMSBuild.bat, this is only part of its capabilities which can also be used to check itself too.

For example, to validate itself:

hMSBuild -GetNuTool ~& svc.gnt -sha1-cmp hMSBuild.bat sha1 -package-as-path

Where sha1 is the checksum from the official distribution. Also, the official package (gnt +hMSBuild) provides validate.hMSBuild.bat; this is wrapper of the command above.

How safe is it?

Since the testing logic is part of the GetNuTool's core feature (read here), it is located inside hMSBuild.bat. This way improves control over unexpected changes, however, it still cannot fully guarantee automatic protection against third party interference directly into the hMSBuild.bat.

Same for env protected properties (n. GetNuTool 1.10+); this improves control over unexpected modification in environment when processing at runtime, but this of course cannot stop direct modifications of the code. Keep this in mind.

Contributing

hMSBuild is waiting for your awesome contributions!

About

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

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

Contributors 3

  •  
  •  
  •