Skip to content

Commit

Permalink
Updated to VS 2022.
Browse files Browse the repository at this point in the history
  • Loading branch information
azchohfi committed Nov 17, 2021
1 parent ba2a05d commit f3e6bd1
Show file tree
Hide file tree
Showing 7 changed files with 284 additions and 22 deletions.
13 changes: 2 additions & 11 deletions ColorCode.UWP/ColorCode.UWP.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
<Project Sdk="MSBuild.Sdk.Extras">

<PropertyGroup>
<TargetFramework>uap10.0.16299</TargetFramework>
<TargetFramework>uap10.0.18362</TargetFramework>
<RootNamespace>ColorCode</RootNamespace>
<AssemblyName>ColorCode.UWP</AssemblyName>
<Title>ColorCode.UWP</Title>
<Description>Contains the RichTextBlockFormatter, for rendering the Colorized Code to a RichTextBlock.</Description>
<PackageTags>ColorCode Syntax Highlighting SyntaxHighlighting Formatting UWP RichTextBlock Document InlineCollection</PackageTags>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
<DebugType>Portable</DebugType>
</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 3 additions & 2 deletions ColorCode.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30104.148
# Visual Studio Version 17
VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ColorCode.HTML", "ColorCode.HTML\ColorCode.HTML.csproj", "{33A3FB96-F1EB-4AF0-94E0-F629E1F574A8}"
EndProject
Expand All @@ -20,6 +20,7 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A4B1B99B-FC3A-4C76-8B46-B96723829FD2}"
ProjectSection(SolutionItems) = preProject
azure-pipelines.yml = azure-pipelines.yml
build\build.cake = build\build.cake
ColorCode.snk = ColorCode.snk
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
Expand Down
6 changes: 3 additions & 3 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

<!-- UWP Config -->
<PropertyGroup Condition="'$(IsUwpProject)' == 'true'">
<TargetPlatformVersion>10.0.16299.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
<TargetPlatformVersion>10.0.18362.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.18362.0</TargetPlatformMinVersion>
</PropertyGroup>

<!-- WinUI Config -->
Expand Down Expand Up @@ -49,7 +49,7 @@
<Choose>
<When Condition="'$(IsUwpProject)' == 'true' and '$(IsTestProject)' != 'true'">
<ItemGroup>
<PackageReference Include="MSBuild.Sdk.Extras" Version="3.0.23" PrivateAssets="all" />
<PackageReference Include="MSBuild.Sdk.Extras" Version="3.0.38" PrivateAssets="all" />
</ItemGroup>
</When>
</Choose>
Expand Down
21 changes: 17 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ pr:
- rel/*

pool:
vmImage: windows-2019
vmImage: windows-2022

variables:
BuildConfiguration: Release

steps:
- task: BatchScript@1
inputs:
filename: "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Enterprise\\Common7\\Tools\\VsDevCmd.bat"
filename: "C:\\Program Files\\Microsoft Visual Studio\\2022\\Enterprise\\Common7\\Tools\\VsDevCmd.bat"
arguments: -no_logo
modifyEnvironment: true
displayName: Setup Environment Variables
Expand All @@ -38,9 +38,15 @@ steps:
- task: UseDotNet@2
displayName: 'Install .NET Core SDK'
inputs:
version: 5.0.402
version: 5.0.403
performMultiLevelLookup: true

# Workaround for VS2022 in CI Builds
- bash: dotnet tool update -g dotnet-vs
- bash: vs modify --rel -sku:enterprise --quiet +Microsoft.Component.MSBuild +Microsoft.VisualStudio.Component.ManagedDesktop.Core +Microsoft.NetCore.Component.DevelopmentTools +Microsoft.VisualStudio.Workload.UniversalBuildTools +Microsoft.VisualStudio.ComponentGroup.UWP.BuildTools +Microsoft.VisualStudio.Workload.MSBuildTools +Microsoft.VisualStudio.Workload.ManagedDesktopBuildTools +Microsoft.VisualStudio.Component.Windows10SDK +Microsoft.VisualStudio.Component.Windows10SDK.18362 +Microsoft.VisualStudio.Component.Windows10SDK.19041 +Microsoft.VisualStudio.Component.Windows10SDK.20348 +Microsoft.VisualStudio.Component.Windows10SDK.22000 +Microsoft.VisualStudio.Workload.Universal

- powershell: .\build\Install-WindowsSdkISO.ps1 18362

- task: DotNetCoreCLI@2
inputs:
command: custom
Expand All @@ -66,4 +72,11 @@ steps:
inputs:
pathToPublish: .\build\nupkg
artifactType: container
artifactName: Packages
artifactName: Packages

- task: PublishPipelineArtifact@1
displayName: Publish BinLog
inputs:
targetPath: .\build\msbuild.binlog
artifactName: BinLog
condition: always()
256 changes: 256 additions & 0 deletions build/Install-WindowsSdkISO.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
[CmdletBinding()]
param([Parameter(Mandatory = $true)]
[string]$buildNumber)

# Ensure the error action preference is set to the default for PowerShell3, 'Stop'
$ErrorActionPreference = 'Stop'

# Constants
$WindowsSDKOptions = @("OptionId.UWPCpp")
$WindowsSDKRegPath = "HKLM:\Software\Microsoft\Windows Kits\Installed Roots"
$WindowsSDKRegRootKey = "KitsRoot10"
$WindowsSDKVersion = "10.0.$buildNumber.0"
$WindowsSDKInstalledRegPath = "$WindowsSDKRegPath\$WindowsSDKVersion\Installed Options"
$StrongNameRegPath = "HKLM:\SOFTWARE\Microsoft\StrongName\Verification"
$PublicKeyTokens = @("31bf3856ad364e35")

function Download-File {
param ([string] $outDir,
[string] $downloadUrl,
[string] $downloadName)

$downloadPath = Join-Path $outDir "$downloadName.download"
$downloadDest = Join-Path $outDir $downloadName
$downloadDestTemp = Join-Path $outDir "$downloadName.tmp"

Write-Host -NoNewline "Downloading $downloadName..."

try {
$webclient = new-object System.Net.WebClient
$webclient.DownloadFile($downloadUrl, $downloadPath)
}
catch [System.Net.WebException] {
Write-Host
Write-Warning "Failed to fetch updated file from $downloadUrl"
if (!(Test-Path $downloadDest)) {
throw "$downloadName was not found at $downloadDest"
}
else {
Write-Warning "$downloadName may be out of date"
}
}

Unblock-File $downloadPath

$downloadDestTemp = $downloadPath;

# Delete and rename to final dest
if (Test-Path -PathType Container $downloadDest) {
[System.IO.Directory]::Delete($downloadDest, $true)
}

Move-Item -Force $downloadDestTemp $downloadDest
Write-Host "Done"

return $downloadDest
}

function Get-ISODriveLetter {
param ([string] $isoPath)

$diskImage = Get-DiskImage -ImagePath $isoPath
if ($diskImage) {
$volume = Get-Volume -DiskImage $diskImage

if ($volume) {
$driveLetter = $volume.DriveLetter
if ($driveLetter) {
$driveLetter += ":"
return $driveLetter
}
}
}

return $null
}

function Mount-ISO {
param ([string] $isoPath)

# Check if image is already mounted
$isoDrive = Get-ISODriveLetter $isoPath

if (!$isoDrive) {
Mount-DiskImage -ImagePath $isoPath -StorageType ISO | Out-Null
}

$isoDrive = Get-ISODriveLetter $isoPath
Write-Verbose "$isoPath mounted to ${isoDrive}:"
}

function Dismount-ISO {
param ([string] $isoPath)

$isoDrive = (Get-DiskImage -ImagePath $isoPath | Get-Volume).DriveLetter

if ($isoDrive) {
Write-Verbose "$isoPath dismounted"
Dismount-DiskImage -ImagePath $isoPath | Out-Null
}
}

function Disable-StrongName {
param ([string] $publicKeyToken = "*")

reg ADD "HKLM\SOFTWARE\Microsoft\StrongName\Verification\*,$publicKeyToken" /f | Out-Null
if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") {
reg ADD "HKLM\SOFTWARE\Wow6432Node\Microsoft\StrongName\Verification\*,$publicKeyToken" /f | Out-Null
}
}

function Test-Admin {
$identity = [Security.Principal.WindowsIdentity]::GetCurrent()
$principal = New-Object Security.Principal.WindowsPrincipal $identity
$principal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
}

function Test-RegistryPathAndValue {
param (
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $path,
[parameter(Mandatory = $true)]
[ValidateNotNullOrEmpty()]
[string] $value)

try {
if (Test-Path $path) {
Get-ItemProperty -Path $path | Select-Object -ExpandProperty $value -ErrorAction Stop | Out-Null
return $true
}
}
catch {
}

return $false
}

function Test-InstallWindowsSDK {
$retval = $true

if (Test-RegistryPathAndValue -Path $WindowsSDKRegPath -Value $WindowsSDKRegRootKey) {
# A Windows SDK is installed
# Is an SDK of our version installed with the options we need?
if (Test-RegistryPathAndValue -Path $WindowsSDKInstalledRegPath -Value "$WindowsSDKOptions") {
# It appears we have what we need. Double check the disk
$sdkRoot = Get-ItemProperty -Path $WindowsSDKRegPath | Select-Object -ExpandProperty $WindowsSDKRegRootKey
if ($sdkRoot) {
if (Test-Path $sdkRoot) {
$refPath = Join-Path $sdkRoot "References\$WindowsSDKVersion"
if (Test-Path $refPath) {
$umdPath = Join-Path $sdkRoot "UnionMetadata\$WindowsSDKVersion"
if (Test-Path $umdPath) {
# Pretty sure we have what we need
$retval = $false
}
}
}
}
}
}

return $retval
}

function Test-InstallStrongNameHijack {
foreach ($publicKeyToken in $PublicKeyTokens) {
$key = "$StrongNameRegPath\*,$publicKeyToken"
if (!(Test-Path $key)) {
return $true
}
}

return $false
}

Write-Host -NoNewline "Checking for installed Windows SDK $WindowsSDKVersion..."
$InstallWindowsSDK = Test-InstallWindowsSDK
if ($InstallWindowsSDK) {
Write-Host "Installation required"
}
else {
Write-Host "INSTALLED"
}

$StrongNameHijack = Test-InstallStrongNameHijack
Write-Host -NoNewline "Checking if StrongName bypass required..."

if ($StrongNameHijack) {
Write-Host "REQUIRED"
}
else {
Write-Host "Done"
}

if ($StrongNameHijack -or $InstallWindowsSDK) {
if (!(Test-Admin)) {
Write-Host
throw "ERROR: Elevation required"
}
}

if ($InstallWindowsSDK) {
# Static(ish) link for Windows SDK
# Note: there is a delay from Windows SDK announcements to availability via the static link
$uri = "https://software-download.microsoft.com/download/sg/Windows_InsiderPreview_SDK_en-us_$($buildNumber)_1.iso";

if ($null -eq $env:TEMP) {
$env:TEMP = Join-Path $env:SystemDrive 'temp'
}

$winsdkTempDir = Join-Path $env:TEMP "WindowsSDK"

if (![System.IO.Directory]::Exists($winsdkTempDir)) {
[void][System.IO.Directory]::CreateDirectory($winsdkTempDir)
}

$file = "winsdk_$buildNumber.iso"

Write-Verbose "Getting WinSDK from $uri"
$downloadFile = Download-File $winsdkTempDir $uri $file

# TODO Check if zip, exe, iso, etc.
try {
Write-Host -NoNewline "Mounting ISO $file..."
Mount-ISO $downloadFile
Write-Host "Done"

$isoDrive = Get-ISODriveLetter $downloadFile

if (Test-Path $isoDrive) {
Write-Host -NoNewLine "Installing WinSDK..."

$setupPath = Join-Path "$isoDrive" "WinSDKSetup.exe"
Start-Process -Wait $setupPath "/features $WindowsSDKOptions /q"
Write-Host "Done"
}
else {
throw "Could not find mounted ISO at ${isoDrive}"
}
}
finally {
Write-Host -NoNewline "Dismounting ISO $file..."
# Dismount-ISO $downloadFile
Write-Host "Done"
}
}

if ($StrongNameHijack) {
Write-Host -NoNewline "Disabling StrongName for Windows SDK..."

foreach ($key in $PublicKeyTokens) {
Disable-StrongName $key
}

Write-Host "Done"
}
3 changes: 2 additions & 1 deletion build/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#addin nuget:?package=Cake.FileHelpers&version=4.0.1
#addin nuget:?package=Cake.Powershell&version=1.0.1
#addin nuget:?package=Cake.GitVersioning&version=3.4.216
#addin nuget:?package=Cake.GitVersioning&version=3.4.244

#tool nuget:?package=vswhere&version=2.8.4

Expand Down Expand Up @@ -147,6 +147,7 @@ Task("Build")
.SetConfiguration("Release")
.WithTarget("Pack")
.WithProperty("GenerateLibraryLayout", "true")
.EnableBinaryLogger()
.WithProperty("PackageOutputPath", nupkgDir);

UpdateToolsPath(buildSettings);
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"msbuild-sdks": {
"MSBuild.Sdk.Extras": "3.0.23"
"MSBuild.Sdk.Extras": "3.0.38"
}
}

0 comments on commit f3e6bd1

Please sign in to comment.