Repository navigation
Expand file tree
/
Copy pathbuild-sourcegenerator.ps1
More file actions
105 lines (83 loc) · 5.37 KB
/
Copy pathbuild-sourcegenerator.ps1
File metadata and controls
105 lines (83 loc) · 5.37 KB
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
[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"
# Source Generator(CodegenCS.SourceGenerator)
# How to run: .\build-sourcegenerator.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.sourcegenerator"
# CompilerServer: server failed - server rejected the request due to analyzer / generator issues 'analyzer assembly '<source>\CodegenCS\src\SourceGenerator\CodegenCS.SourceGenerator\bin\Release\netstandard2.0\CodegenCS.SourceGenerator.dll'
# has MVID '<someguid>' but loaded assembly 'C:\Users\<user>\AppData\Local\Temp\VBCSCompiler\AnalyzerAssemblyLoader\<randompath>\CodegenCS.SourceGenerator.dll' has MVID '<otherguid>'' - SampleProjectWithSourceGenerator (netstandard2.0)
gci $env:TEMP -r -filter CodegenCS.SourceGenerator.dll -ErrorAction Ignore | Remove-Item -Force -Recurse -ErrorAction Ignore
gci "$($env:TEMP)\VBCSCompiler\AnalyzerAssemblyLoader" -r -ErrorAction Ignore | Remove-Item -Force -Recurse -ErrorAction Ignore
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 .\SourceGenerator\CodegenCS.SourceGenerator\CodegenCS.SourceGenerator.csproj
& $msbuild ".\SourceGenerator\CodegenCS.SourceGenerator\CodegenCS.SourceGenerator.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.SourceGenerator.$version.nupkg" }
if (Test-Path $7z) {
$zipContents = (& $7z l -ba -slt .\packages-local\CodegenCS.SourceGenerator.$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" }
}
#dotnet clean ..\Samples\SourceGenerator1\SourceGenerator1.csproj
dotnet restore ..\Samples\SourceGenerator1\SourceGenerator1.csproj
& $msbuild "..\Samples\SourceGenerator1\SourceGenerator1.csproj" `
/t:Restore /t:Rebuild `
/p:Configuration=$configuration `
/verbosity:normal
if (! $?) { throw "msbuild failed" }
Write-Host "------------" -ForegroundColor Yellow
C:\ProgramData\chocolatey\lib\dnspyex\tools\dnSpy.Console.exe ..\Samples\SourceGenerator1\bin\$configuration\netstandard2.0\SourceGenerator1.dll -t MyFirstClass
C:\ProgramData\chocolatey\lib\dnspyex\tools\dnSpy.Console.exe ..\Samples\SourceGenerator1\bin\$configuration\netstandard2.0\SourceGenerator1.dll -t AnotherSampleClass # should show some methods that were generated on the fly
if (! $?) { throw "Template failed (classes were not added to the compilation)" }
Pop-Location