-
Notifications
You must be signed in to change notification settings - Fork 899
source index using SourceLink.exe #1009
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@ctaggart Hmmm. Something is still wrong with the build process. My bad. @GeertvanHorrik was nice enough to help us ease the source indexing integration, but I've just discovered that we're not there yet. Let me explain our build process a bit better. Tests are run with a specific However, we wouldn't want to publish the NuGet package with the result of this build. Thus we have to rebuild it without the extra define. Published NuGet package should include the LibGit2sharp commit sha so that we're able to output it when
Would everything works as intended, instead of Would you be so kind as to apply the following patch to this PR and see if that solves the issue? diff --git a/appveyor.yml b/appveyor.yml
index 0fc2107..0201617 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -54,9 +54,6 @@ cache:
before_build:
- nuget restore "%APPVEYOR_BUILD_FOLDER%\LibGit2Sharp.sln"
-after_build:
-- ps: sourcelink index -u 'https://raw.githubusercontent.com/libgit2/libgit2sharp/{0}/%var2%' -pr LibGit2Sharp\LibGit2Sharp.csproj -pp Configuration Release -nf LibGit2Sharp\Core\UniqueIdentifier.cs -nf LibGit2Sharp\Properties\AssemblyInfo.cs
-
build_script:
- msbuild "%APPVEYOR_BUILD_FOLDER%\LibGit2Sharp.sln" /verbosity:normal /p:Configuration=Release /logger:"C:\Program Files\AppVeyor\BuildAgent\Appveyor.MSBuildLogger.dll" /property:ExtraDefine="LEAKS_IDENTIFYING"
@@ -66,7 +63,7 @@ test_script:
on_success:
- ps: |
- & "$env:APPVEYOR_BUILD_FOLDER\nuget.package\BuildNugetPackage.ps1" "$env:APPVEYOR_REPO_COMMIT"
+ & "$env:APPVEYOR_BUILD_FOLDER\nuget.package\BuildNugetPackage.ps1" -commitSha "$env:APPVEYOR_REPO_COMMIT" -postBuild { sourcelink index -u 'https://raw.githubusercontent.com/libgit2/libgit2sharp/{0}/%var2%' -pr LibGit2Sharp\LibGit2Sharp.csproj -pp Configuration Release -nf LibGit2Sharp\Core\UniqueIdentifier.cs -nf LibGit2Sharp\Properties\AssemblyInfo.cs }
Add-Type -Path "$env:APPVEYOR_BUILD_FOLDER\LibGit2Sharp\bin\Release\LibGit2Sharp.dll"
Write-Host "LibGit2Sharp version = $([LibGit2Sharp.GlobalSettings]::Version)" -ForegroundColor "Magenta"
#If ($Env:SHOULD_PUBLISH_NUGET_ARTIFACT -eq $True)
diff --git a/nuget.package/BuildNugetPackage.ps1 b/nuget.package/BuildNugetPackage.ps1
index 8eac5e5..6770c14 100644
--- a/nuget.package/BuildNugetPackage.ps1
+++ b/nuget.package/BuildNugetPackage.ps1
@@ -8,7 +8,8 @@
Param(
[Parameter(Mandatory=$true)]
- [string]$commitSha
+ [string]$commitSha,
+ [scriptblock]$postBuild
)
$ErrorActionPreference = "Stop"
@@ -51,13 +52,25 @@ function Clean-OutputFolder($folder) {
}
}
+# From http://www.dougfinke.com/blog/index.php/2010/12/01/note-to-self-how-to-programmatically-get-the-msbuild-path-in-powershell/
+
+Function Get-MSBuild {
+ $lib = [System.Runtime.InteropServices.RuntimeEnvironment]
+ $rtd = $lib::GetRuntimeDirectory()
+ Join-Path $rtd msbuild.exe
+}
+
#################
$root = Split-Path -Parent -Path $MyInvocation.MyCommand.Definition
$projectPath = Join-Path $root "..\LibGit2Sharp"
+$slnPath = Join-Path $projectPath "..\LibGit2Sharp.sln"
Remove-Item (Join-Path $projectPath "*.nupkg")
+Clean-OutputFolder (Join-Path $projectPath "bin\")
+Clean-OutputFolder (Join-Path $projectPath "obj\")
+
# The nuspec file needs to be next to the csproj, so copy it there during the pack operation
Copy-Item (Join-Path $root "LibGit2Sharp.nuspec") $projectPath
@@ -65,7 +78,14 @@ Push-Location $projectPath
try {
Set-Content -Encoding ASCII $(Join-Path $projectPath "libgit2sharp_hash.txt") $commitSha
- Run-Command { & "$(Join-Path $projectPath "..\Lib\NuGet\Nuget.exe")" Restore "$(Join-Path $projectPath "..\LibGit2Sharp.sln")" }
+ Run-Command { & "$(Join-Path $projectPath "..\Lib\NuGet\Nuget.exe")" Restore "$slnPath" }
+ Run-Command { & (Get-MSBuild) "$slnPath" "/verbosity:minimal" "/p:Configuration=Release" }
+
+ If ($postBuild) {
+ Write-Host -ForegroundColor "Green" "Run post build script..."
+ Run-Command { & ($postBuild) }
+ }
+
Run-Command { & "$(Join-Path $projectPath "..\Lib\NuGet\Nuget.exe")" Pack -Prop Configuration=Release }
}
finally { Provided I didn't mess up too bad, this should solve the problem Disclaime: I'm NOT a PowerShell guy, so there may be better ways to achieve this. |
@ctaggart Could you please apply the changes manually? |
Will do. |
@ctaggart ❤️ I've locally tested the changes by passing a dummy
|
@ctaggart Surprisngly the postbuild trickery seems to be working. However, the paths may require some tweaking (sorry about that)
|
Maybe passing absolute paths starting with |
Based on the output, we can see it is running from the project directly. This is because of Push-Location in BuildNuGetPackage.ps1. It is pretty straight forward to run SourceLink.exe from that directory. Do you have chocolatey installed? If not, install it by running PowerShell as Administrator with: iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1')) Then you can install SourceLink with: cinst SourceLink -version 0.5.0 In a new regular PowerShell window, you can then do cd C:\Projects\libgit2sharp\LibGit2Sharp
SourceLink.exe index `
-pr ./LibGit2Sharp.csproj `
-pp Configuration Release `
-nf Core\UniqueIdentifier.cs `
-nf Properties\AssemblyInfo.cs `
-r .. `
-u 'https://raw.githubusercontent.com/libgit2/libgit2sharp/{0}/%var2%' It is easiest to explain what I did by looking at the help for the The csproj is used to get a list of source files used. We exclude a couple of files that are generated at build time. We say that the repository root is in the parent folder. We say what URL to source index with. SourceLink then verifies that the checksums of the files in the working directory used to create the build match those in the pdb and the git repository. That way, when Visual Studio or other debuggers download the source file from GitHub, the checksum in the pdb and of the download file match. I'l update the pull request. |
@ctaggart That worked perfectly ✨ Thanks for the detailed explanation as well. Could you please uncomment the part that detects if NuGet packages should be published, in While you're at it, please squash all the commits into one and we'll get this merged! |
What is the best way to squash? It is not something I've done. I looked up stackoverflow and this is what I came up with:
Git is hanging on the last statement. Any ideas? |
Provided your commit has been created, you'd have to force push to update the remote head. |
I upgraded git and tried again and it looks like it worked. git version 1.8.5.2.msysgit.0 |
Published as NuGet pre-release package |
fixes #876, changes based on #1003
https://ci.appveyor.com/project/ctaggart/libgit2sharp/build/3/job/odbyu9n88cjfgw1i#L123

I've addressed @nulltoken's concern from #465 with a
sourcelink checksums --check
command you can verify the pdb file source index works.