-
-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathbuild-msbuild.ps1
164 lines (122 loc) · 7.58 KB
/
build-msbuild.ps1
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
[cmdletbinding()]
param(
[Parameter(Mandatory=$False)][ValidateSet('Release','Debug')][string]$configuration
)
$ErrorActionPreference="Stop"
$version = "3.5.2"
$nugetPE = "C:\ProgramData\chocolatey\bin\NuGetPackageExplorer.exe"
$7z = "C:\Program Files\7-Zip\7z.exe"
# MSBuild Task (CodegenCS.MSBuild)
# How to run: .\build-msbuildtask.ps1
. $PSScriptRoot\build-include.ps1
$scriptpath = $MyInvocation.MyCommand.Path
$dir = Split-Path $scriptpath
Push-Location $dir
Remove-Item -Recurse -Force -ErrorAction Ignore "$env:HOMEDRIVE$env:HOMEPATH\.nuget\packages\codegencs.msbuild"
gci $env:TEMP -r -filter CodegenCS.MSBuild.dll -ErrorAction Ignore | Remove-Item -Force -Recurse -ErrorAction Ignore
#gci "$($env:TEMP)\VBCSCompiler\AnalyzerAssemblyLoader" -r -ErrorAction Ignore | Remove-Item -Force -Recurse -ErrorAction Ignore
gci .\packages\ -filter CodegenCS.MSBuild.* | Remove-Item -Force -Recurse -ErrorAction Ignore # non-sdk projects will cache packages here
if (-not $PSBoundParameters.ContainsKey('configuration'))
{
if (Test-Path Release.snk) { $configuration = "Release"; } else { $configuration = "Debug"; }
}
Write-Host "Using configuration $configuration..." -ForegroundColor Yellow
# Unfortunately Roslyn Analyzers, Source Generators, and MS Build Tasks they all have terrible support for referencing other assemblies without having those added (and conflicting) to the client project
# To get a Nupkg with SourceLink/Deterministic PDB we have to embed the extract the PDBs from their symbol packages so we can embed them into our published package
mkdir .\ExternalSymbolsToEmbed -EA Ignore | Out-Null
$snupkgs = @(
"interpolatedcolorconsole.1.0.3.snupkg",
"newtonsoft.json.13.0.3.snupkg",
"nswag.core.14.0.7.snupkg",
"nswag.core.yaml.14.0.7.snupkg",
"njsonschema.11.0.0.snupkg",
"njsonschema.annotations.11.0.0.snupkg"
)
foreach ($snupkg in $snupkgs){
Write-Host $snupkg
if (-not (Test-Path ".\ExternalSymbolsToEmbed\$snupkg")) {
curl "https://globalcdn.nuget.org/symbol-packages/$snupkg" -o ".\ExternalSymbolsToEmbed\$snupkg"
}
}
copy .\packages-local\System.CommandLine.2.0.0-codegencs.snupkg .\ExternalSymbolsToEmbed\
copy .\packages-local\System.CommandLine.NamingConventionBinder.2.0.0-codegencs.snupkg .\ExternalSymbolsToEmbed\
$snupkgs = gci .\ExternalSymbolsToEmbed\*.snupkg
foreach ($snupkg in $snupkgs){
$name = $snupkg.Name
$name = $name.Substring(0, $name.Length-7)
$zipContents = (& $7z l -ba -slt "ExternalSymbolsToEmbed\$name.snupkg" | Out-String) -split"`r`n"
$zipContents | Select-String "Path = "
mkdir "ExternalSymbolsToEmbed\$name\" -ea Ignore | out-null
& $7z x "ExternalSymbolsToEmbed\$name.snupkg" "-oExternalSymbolsToEmbed\$name\" *.pdb -r -aoa
}
dotnet restore .\MSBuild\CodegenCS.MSBuild\CodegenCS.MSBuild.csproj
& $msbuild ".\MSBuild\CodegenCS.MSBuild\CodegenCS.MSBuild.csproj" `
/t:Restore /t:Build /t:Pack `
/p:PackageOutputPath="..\..\packages-local\" `
/p:Configuration=$configuration `
/verbosity:minimal `
/p:IncludeSymbols=true `
/p:ContinuousIntegrationBuild=true `
if (! $?) { throw "msbuild failed" }
#if (Test-Path $nugetPE) { & $nugetPE ".\packages-local\CodegenCS.MSBuild.$version.nupkg" }
if (Test-Path $7z) {
$zipContents = (& $7z l -ba -slt .\packages-local\CodegenCS.MSBuild.$version.nupkg | Out-String) -split"`r`n"
Write-Host "------------" -ForegroundColor Yellow
$zipContents|Select-String "Path ="
sleep 2
# sanity check: nupkg should have debug-build dlls, pdb files, source files, etc.
if (-not ($zipContents|Select-String "Path = "|Select-String "CodegenCS.Core.dll")) { throw "msbuild failed" }
if (-not ($zipContents|Select-String "Path = "|Select-String "CodegenCS.Core.pdb") -and $configuration -eq "Debug") { throw "msbuild failed" }
}
# Visual Studio Design-Time-Builds were keeping msbuild running and eventually building (and locking) our templates. I think this is gone, now that Design-Time-Builds were blocked in CodegenCS.MSBuild.targets
# handle codegencs.core.dll
#taskkill /f /im msbuild.exe
# If task fails due to missing dependencies then fusion++ might help to identify what's missing: C:\ProgramData\chocolatey\lib\fusionplusplus\tools\Fusion++.exe
# Test with SDK-Project using msbuild (.NET Framework)
del ..\Samples\MSBuild1\*.g.cs
del ..\Samples\MSBuild1\*.generated.cs
#dotnet clean ..\Samples\MSBuild1\MSBuild1.csproj
dotnet restore ..\Samples\MSBuild1\MSBuild1.csproj
& $msbuild "..\Samples\MSBuild1\MSBuild1.csproj" `
/t:Restore /t:Rebuild `
/p:Configuration=$configuration `
/verbosity:normal
if (! $?) { throw "msbuild failed" }
Write-Host "------------" -ForegroundColor Yellow
if (-not (gci ..\Samples\MSBuild1\*.g.cs)){ throw "Template failed (classes were not added to the compilation)" }
C:\ProgramData\chocolatey\lib\dnspyex\tools\dnSpy.Console.exe ..\Samples\MSBuild1\bin\$configuration\net8.0\MSBuild1.dll -t MyFirstClass
if (! $?) { throw "Template failed (classes were not added to the compilation)" }
#C:\ProgramData\chocolatey\lib\dnspyex\tools\dnSpy.exe ..\Samples\MSBuild1\bin\$configuration\net8.0\MSBuild1.dll
# Test with SDK-Project using dotnet build (.NET Core)
del ..\Samples\MSBuild1\*.g.cs
del ..\Samples\MSBuild1\*.generated.cs
#dotnet clean ..\Samples\MSBuild1\MSBuild1.csproj
dotnet restore ..\Samples\MSBuild1\MSBuild1.csproj
& dotnet build "..\Samples\MSBuild1\MSBuild1.csproj" `
/t:Restore /t:Rebuild `
/p:Configuration=$configuration `
/verbosity:normal
if (! $?) { throw "msbuild failed" }
Write-Host "------------" -ForegroundColor Yellow
if (-not (gci ..\Samples\MSBuild1\*.g.cs)){ throw "Template failed (classes were not added to the compilation)" }
C:\ProgramData\chocolatey\lib\dnspyex\tools\dnSpy.Console.exe ..\Samples\MSBuild1\bin\$configuration\net8.0\MSBuild1.dll -t MyFirstClass
if (! $?) { throw "Template failed (classes were not added to the compilation)" }
#C:\ProgramData\chocolatey\lib\dnspyex\tools\dnSpy.exe ..\Samples\MSBuild1\bin\$configuration\net8.0\MSBuild1.dll
# Test with non-SDK-Project (Microsoft Framework Web Application) using msbuild (.NET Framework)
del ..\Samples\MSBuild2\*.g.cs
del ..\Samples\MSBuild2\*.generated.cs
#dotnet clean ..\Samples\MSBuild2\WebApplication.csproj
#dotnet restore ..\Samples\MSBuild2\WebApplication.csproj
& .\nuget.exe restore -PackagesDirectory .\packages ..\Samples\MSBuild2\WebApplication.csproj
& $msbuild "..\Samples\MSBuild2\WebApplication.csproj" `
/t:Restore /t:Rebuild `
/p:Configuration=$configuration `
/verbosity:normal
if (! $?) { throw "msbuild failed" }
Write-Host "------------" -ForegroundColor Yellow
if (-not (gci ..\Samples\MSBuild2\*.g.cs)){ throw "Template failed (classes were not added to the compilation)" }
C:\ProgramData\chocolatey\lib\dnspyex\tools\dnSpy.Console.exe ..\Samples\MSBuild2\bin\WebApplication.dll -t MyFirstClass
if (! $?) { throw "Template failed (classes were not added to the compilation)" }
#C:\ProgramData\chocolatey\lib\dnspyex\tools\dnSpy.exe ..\Samples\MSBuild2\bin\WebApplication.dll
# Test with non-SDK-Project (Microsoft Framework Web Application) using dotnet build (.NET Core) - doesnt work
Pop-Location