terminal/tools/razzle.cmd
David Machaj 036cc284bd
Terminal would benefit from having a single canonical version number for each of its NuGet dependencies (#12707)
These changes are purely a refactoring of the build files.  There should
be no difference to the compiled result or runtime behavior.  

Currently there are packages.config files in lots of directories, with
those same projects referencing props/targets from packages/ with a
version string in the path.  This is frustrating because version changes
or new dependencies require updating lots and lots of build files
identically.  There is also the possibility of error where locations are
missed.

With these changes there is a single canonical nuget configuration that
takes effect for all of OpenConsole.sln.  Updating version numbers
should be limited to a single set of global files.

The changes were done incrementally but the result is basically that
dep\nuget\packages.config serves as the global NuGet dependency list.  A
pair of common build files (common.nugetversions.props and
common.nugetversions.targets) were added to contain the various imports
and error checks.  There is also a special build target to ensure that
the restore happens before builds even though a given directory doesn't
have a packages.config for Visual Studio to observe.  

These new *.nugetversions.* files are imported in pretty much every
vcxproj/csproj in the solution in the appropriate place to satisfy the
need for packages.  There are opt-in configuration values (e.g.
`TerminalCppWinrt=true`) that must be set to opt into a given
dependency.  Adding a new dependency is just a matter of adding a new
opt-in value.  The ordering of include does matter, which was a
difficult challenge to realize and address.

There was also a preexisting issue in 3 test projects where
cppwinrt.props was included but not cppwinrt.targets.  By consolidating
things globally that "error" was fixed, but broke the build in a way
that was very confusing.  Those projects don't need the cppwinrt targets
so they were opted out of the cppwinrt build files entirely to fix the
breaks and get back to previous behavior.

There are two notable exceptions to this canonical versioning.  The
first is that there are dueling XAML 2.7 dependencies.  I avoided that
by leaving those as per-project package.config entries.  The second is
that any projects outside of the .sln (such as the Island samples) were
not touched.

## Validation Steps Performed
The primary validation is that the solution builds without errors.  That
is what I'm seeing (x64|Debug).  I also ran `git clean -fdx` from the
root of the repo to wipe it to clean and then opened the solution and
was able to build successfully.  The project F5 deploys and looks fine
to me with just a cursory glance.  The tests also largely pass (7418
pass, 188 fail, 14 other) which is as good or better than the baseline I
established from a clean clone.

Closes #12708
2022-03-28 18:31:36 +00:00

127 lines
3.6 KiB
Batchfile

@echo off
echo Setting up dev environment...
rem Open Console build environment setup
rem Adds msbuild to your path, and adds the open\tools directory as well
rem This recreates what it's like to be an actual windows developer!
rem skip the setup if we're already ready.
if not "%OpenConBuild%" == "" goto :END
rem Add Opencon build scripts to path
set PATH=%PATH%;%~dp0;
rem add some helper envvars - The Opencon root, and also the processor arch, for output paths
set OPENCON_TOOLS=%~dp0
rem The opencon root is at ...\open\tools\, without the last 7 chars ('\tools\')
set OPENCON=%OPENCON_TOOLS:~0,-7%
rem Add nuget to PATH
set PATH=%PATH%%OPENCON%\dep\nuget;
rem Run nuget restore so you can use vswhere
nuget restore %OPENCON%\OpenConsole.sln -Verbosity quiet
nuget restore %OPENCON%\dep\nuget\packages.config -Verbosity quiet
:FIND_MSBUILD
set MSBUILD=
rem GH#1313: If msbuild is already on the path, we don't need to look for it.
for %%X in (msbuild.exe) do (set MSBUILD=%%~$PATH:X)
if defined MSBUILD (
echo Using MsBuild at %MSBUILD% which was already on the path.
goto :FOUND_MSBUILD
)
rem Find vswhere
rem from https://github.com/microsoft/vs-setup-samples/blob/master/tools/vswhere.cmd
for /f "usebackq delims=" %%I in (`dir /b /aD /o-N /s "%~dp0..\packages\vswhere*" 2^>nul`) do (
for /f "usebackq delims=" %%J in (`where /r "%%I" vswhere.exe 2^>nul`) do (
set VSWHERE=%%J
)
)
if not defined VSWHERE (
echo Could not find vswhere on your machine. Please set the VSWHERE variable to the location of vswhere.exe and run razzle again.
goto :EXIT
)
rem Add path to MSBuild Binaries
rem
rem We're going to always prefer prerelease version of VS. This lets people who
rem are using VS 2022 use that from the commandline over the 2019 version. This
rem will use whatever the newest version of VS is, regardless if it's stable or
rem not.
rem
for /f "usebackq tokens=*" %%B in (`%VSWHERE% -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild\**\Bin\MSBuild.exe 2^>nul`) do (
set MSBUILD=%%B
)
if not defined MSBUILD (
echo Could not find MsBuild on your machine. Please set the MSBUILD variable to the location of MSBuild.exe and run razzle again.
goto :EXIT
)
:FOUND_MSBUILD
set PATH=%PATH%%MSBUILD%\..;
if "%PROCESSOR_ARCHITECTURE%" == "AMD64" (
set ARCH=x64
set PLATFORM=x64
) else (
set ARCH=x86
set PLATFORM=Win32
)
set DEFAULT_CONFIGURATION=Debug
rem call .razzlerc - for your generic razzle environment stuff
if exist "%OPENCON_TOOLS%\.razzlerc.cmd" (
call %OPENCON_TOOLS%\.razzlerc.cmd
) else (
(
echo @echo off
echo.
echo rem This is your razzlerc file. It can be used for default dev environment setup.
) > %OPENCON_TOOLS%\.razzlerc.cmd
)
rem if there are args, run them. This can be used for additional env. customization,
rem especially on a per shortcut basis.
:ARGS_LOOP
if (%1) == () goto :POST_ARGS_LOOP
if (%1) == (dbg) (
set DEFAULT_CONFIGURATION=Debug
shift
goto :ARGS_LOOP
)
if (%1) == (rel) (
set DEFAULT_CONFIGURATION=Release
shift
goto :ARGS_LOOP
)
if (%1) == (x86) (
set ARCH=x86
set PLATFORM=Win32
shift
goto :ARGS_LOOP
)
if exist %1 (
call %1
) else (
echo Could not locate "%1"
)
shift
goto :ARGS_LOOP
:POST_ARGS_LOOP
set TAEF=%OPENCON%\packages\Microsoft.Taef.10.60.210621002\build\Binaries\%ARCH%\TE.exe
rem Set this envvar so setup won't repeat itself
set OpenConBuild=true
:END
echo The dev environment is ready to go!
:EXIT