-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBuildHyperV.cmd
112 lines (92 loc) · 3.42 KB
/
BuildHyperV.cmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
:: Disable command output
@echo OFF
:: Set variables
@set VS2022_DIRECTORY="C:\Program Files\Microsoft Visual Studio\2022\Community\"
@set ORIG_DRIVE=%CD:~0,2%
@set ORIG_DIRECTORY=%CD%
@set VHD="%CD%\ZeroOS.BootLoader.vhdx"
@set VDI="%CD%\ZeroOS.BootLoader.vdi"
@set VHD_SCRIPT="%CD%\diskpart.txt"
@set HYPER-V_DIRECTORY="C:\ZeroOSTestVM"
:: Delete existing files that are needed to be overwritten
@del %VHD% >nul 2>&1
@del %VHD_SCRIPT% >nul 2>&1
@del ZeroOS.BootLoader.ilexe >nul 2>&1
@del ZeroOS.BootLoader.obj >nul 2>&1
@del ZeroOS.BootLoader.map >nul 2>&1
@del ZeroOS.BootLoader.pdb >nul 2>&1
@del BOOTX64.EFI >nul 2>&1
@del ZeroOS.BootLoader.vhdx >nul 2>&1
:: Clean up exiting files instead of building
@if "%1" == "clean" (
exit /b
)
:: Change directory if current direcetory isnt C drive
if NOT "%ORIG_DRIVE%" == "C:" (
C:
)
:: Check if Visual Studio 2022 Community exist
if NOT exist %VS2022_DIRECTORY% (
echo Visual Studio 2022 Community does not exist.
pause
exit /b
)
:: Run Dev CMD for VS 2022
call %VS2022_DIRECTORY%"\Common7\Tools\VsDevCmd.bat"
:: Change to original drive
%ORIG_DRIVE%
:: Change to original directory
cd %ORIG_DIRECTORY%
:: Check for build requirements
@set ILCPATH=%DROPPATH%\tools
@if not exist %ILCPATH%\ilc.exe (
echo The DROPPATH environment variable is not set. Required: %ILCPATH%\ilc.exe
exit /B
)
@where csc >nul 2>&1
@if ERRORLEVEL 1 (
echo csc.exe does not exist in the Developer Prompt directory.
exit /B
)
if exist %HYPER-V_DIRECTORY% (
powershell -command "Stop-VM -Name ZeroOSTestVM -TurnOff"
)
:: Run CSharp Compiler
csc /nologo /debug:embedded /noconfig /nostdlib /runtimemetadataversion:v4.0.30319 ZeroOS.BootLoader/Program.cs ZeroOS.BootLoader/EFI/CLI.cs ZeroOS.BootLoader/EFI/UEFIBaseType.cs ZeroOS.BootLoader/EFI/UEFISpec.cs ZeroOS.BootLoader/EFI/Enums/EFI_COLORS.cs ZeroOS.BootLoader/EFI/Enums/EFI_STATUS.cs ZeroOS.BootLoader/CLR/ILC_COMPLIANTS/Internal.Runtime.CompilerHelpers.cs ZeroOS.BootLoader/CLR/ILC_COMPLIANTS/Internal.TypeSystem.cs ZeroOS.BootLoader/CLR/ILC_COMPLIANTS/System.cs ZeroOS.BootLoader/CLR/System.cs ZeroOS.BootLoader/CLR/System.Runtime.InteropServices.cs /out:ZeroOS.BootLoader.ilexe /langversion:latest /unsafe
%ILCPATH%\ilc ZeroOS.BootLoader.ilexe -o ZeroOS.BootLoader.obj --systemmodule ZeroOS.BootLoader --map ZeroOS.BootLoader.map -O
link /nologo /subsystem:EFI_APPLICATION ZeroOS.BootLoader.obj /entry:EfiMain /incremental:no /out:BOOTX64.EFI
:: Create and attach virtual disk
@(
echo create vdisk file=%VHD% maximum=500
echo select vdisk file=%VHD%
echo attach vdisk
echo convert gpt
echo create partition efi size=100
echo format quick fs=fat32 label="System"
echo assign letter="X"
echo exit
)>%VHD_SCRIPT%
:: Run disk part
diskpart /s %VHD_SCRIPT%
:: Archive EFI
xcopy BOOTX64.EFI X:\EFI\BOOT\
:: Detach virtual disk
@(
echo select vdisk file=%VHD%
echo select partition 2
echo remove letter=X
echo detach vdisk
echo exit
)>%VHD_SCRIPT%
:: Run disk part
diskpart /s %VHD_SCRIPT%
:: Create Hyper-V VM if it doesn't exist
if NOT exist %HYPER-V_DIRECTORY% (
powershell -command "New-VM -Name ZeroOSTestVM -Generation 2 -MemoryStartupBytes 1GB -BootDevice VHD -VHDPath '%VHD%' -Path '%HYPER-V_DIRECTORY%'"
powershell -command "Set-VMFirmware ZeroOSTestVM -EnableSecureBoot Off"
)
:: Run Hyper-V VM
powershell -command "Start-VM -Name ZeroOSTestVM"
powershell -command "vmconnect.exe localhost ZeroOSTestVM"
:: Wait for input and exit
pause