Skip to content

Commit

Permalink
Code sign assemblies.
Browse files Browse the repository at this point in the history
Release 1.0.5
  • Loading branch information
lovettchris committed Apr 14, 2023
1 parent c607909 commit 12aad29
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 27 deletions.
47 changes: 47 additions & 0 deletions src/BUILD.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
@echo off

WHERE msbuild >NUL 2>NUL
IF ERRORLEVEL 1 goto :setup
goto :powershell

:setup
if "%VS140COMNTOOLS%" NEQ "" (
call "%VS140COMNTOOLS%vsvars32.bat"
goto :powershell
)
if "%VS150COMNTOOLS%" NEQ "" (
call "%VS150COMNTOOLS%VsDevCmd.bat"
goto :powershell
)
if "%VS160COMNTOOLS%" NEQ "" (
call "%VS160COMNTOOLS%VsDevCmd.bat"
goto :powershell
) else (
echo "Run this script from the Visual Studio Developer Command Prompt"
exit /B 1
)

:powershell
WHERE pwsh >NUL 2>NUL
IF ERRORLEVEL 1 (
echo "Installing 'pwsh' (PowerShell Core)"
dotnet tool install --global powershell
)

pwsh -f Common/fix_versions.ps1

REM Restore NuGet packages:
msbuild -t:restore XmlDiff.sln /verbosity:minimal /p:Configuration=Release "/p:Platform=Any CPU"
if ERRORLEVEL 1 exit /B 1

REM Build XmlDiff:
msbuild XmlDiff.sln /verbosity:minimal /p:Configuration=Release "/p:Platform=Any CPU"
if ERRORLEVEL 1 exit /B 1

if "%MyKeyFile%" == "" goto :eof

REM sign assemblies
pwsh -f Common\full_sign.ps1

REM create .nupkg
nuget pack XmlDiffView\XmlDiff.nuspec
70 changes: 70 additions & 0 deletions src/Common/fix_versions.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path
$RootDir = Split-Path -Parent $ScriptDir
Set-Location $RootDir

$props = Join-Path -Path $RootDir -ChildPath "Common\version.props"
$nuspec = Join-Path -Path $RootDir -ChildPath "XmlDiffView\XmlDiff.nuspec"

function UpdateVersion($line)
{
if ($line -match "\w*\<version\>([^\<]*)\</version\>") {
# this is the SgmlReader.nuspec
return $line.Replace($Matches.1, "$version")
}
elseif ($line -match "\w*\<Version\>([^\<]*)\</Version\>") {
# this is in version.props.
return $line.Replace($Matches.1, "$version")
}
elseif ($line -match "\w*\<FileVersion\>([^\<]*)\</FileVersion\>") {
# this is in version.props.
return $line.Replace($Matches.1, "$version")
}
elseif ($line -match "\w*\<AssemblyVersion\>([^\<]*)\</AssemblyVersion\>") {
# this is in version.props.
return $line.Replace($Matches.1, "$version")
}
elseif ($line -match "\w*\[assembly\: AssemblyVersion\(\`"([^<]*)\`"\)\]") {
return $line.Replace($Matches.1, "$version")
}
elseif ($line -match "\w*\[assembly\: AssemblyFileVersion\(\`"([^<]*)\`"\)\]") {
return $line.Replace($Matches.1, "$version")
}
return $line
}

function FixFile($filename)
{
if ($filename -eq "") {
Write-Error "Missing filename parameter"
Exit 1
}

$nl = [Environment]::NewLine
$versionFile = Join-Path -Path $ScriptDir -ChildPath "version.txt"
$version = Get-Content -Path $versionFile | Join-String -Separator $nl
$version = $version.Trim()

$fullPath = $filename
if (-Not (Test-Path $fullPath)) {
$x = Get-Location
$fullPath = Join-Path -Path $x -ChildPath $filename
}

$localcontent = Get-Content -Path $fullPath | ForEach { UpdateVersion $_ } | Join-String -Separator $nl
$encoding = New-Object System.Text.UTF8Encoding $False

$write = $false
while (-not $write) {
try {
Write-Host "updating version in $filename"
[IO.File]::WriteAllText($filename, $localcontent, $encoding)
$write = $true
} catch {
Write-Host "file locked, trying again in 1 second: $filename"
Start-Sleep -s 1
}
}
}

FixFile($props)
FixFile($nuspec)
21 changes: 21 additions & 0 deletions src/Common/full_sign.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# This script performs the full signing of all the assemblies used in the .nuspec after the build does delay signing
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Path

$testpath = $ScriptDir + "\..\XmlDiff\bin\Release\net46\XmlDiffPatch.dll"
if (-not (Test-Path -Path $testpath)){
Write-Host "Please build release build of XmlDiff.sln"
exit 1
}

$doc = [System.Xml.Linq.XDocument]::Load("$ScriptDir\..\XmlDiffView\XmlDiff.nuspec")
$ns = $doc.Root.Name.Namespace.NamespaceName
foreach ($e in $doc.Root.Descendants()) {
if ($e.Name.LocalName -eq "file") {
$src = $e.Attribute("src").Value
if ($src.EndsWith(".dll") -or $src.EndsWith(".exe")) {
Write-Host "signing $src"
$path = $ScriptDir + "\..\XmlDiffView\" + $src
signtool sign /a /i "Sectigo Public Code Signing CA R36" /t http://timestamp.sectigo.com /fd sha256 $path
}
}
}
9 changes: 9 additions & 0 deletions src/Common/version.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>
<PropertyGroup>
<Company>Lovett Software</Company>
<Copyright>Copyright © Lovett Software</Copyright>
<FileVersion>1.0.5</FileVersion>
<AssemblyVersion>1.0.5</AssemblyVersion>
<Version>1.0.5</Version>
</PropertyGroup>
</Project>
1 change: 1 addition & 0 deletions src/Common/version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.5
11 changes: 8 additions & 3 deletions src/XmlDiff.sln
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
# Visual Studio Version 17
VisualStudioVersion = 17.5.33530.505
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XmlDiff", "XmlDiff\XmlDiff.csproj", "{F4B9C469-315F-47DB-90DB-D0E21170C35B}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "XmlDiffView", "XmlDiffView\XmlDiffView.csproj", "{E7D8D590-B1B7-4D67-91EE-79A5DD569802}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "UnitTests", "UnitTests\UnitTests.csproj", "{D2FBED29-536D-4FA9-94F4-EB72BF89A900}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "UnitTests", "UnitTests\UnitTests.csproj", "{D2FBED29-536D-4FA9-94F4-EB72BF89A900}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A880F19D-4487-4DD8-A987-1FD87FB7E15F}"
ProjectSection(SolutionItems) = preProject
Common\version.props = Common\version.props
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
13 changes: 2 additions & 11 deletions src/XmlDiff/XmlDiff.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../Common/version.props" />
<PropertyGroup>
<TargetFrameworks>netstandard2.1;netstandard2.0;net452;net46;net47;net48;netcoreapp3.1;net6.0</TargetFrameworks>
<DefineConstants>MEASURE_PERF;TRACE;DESCRIPTORS;DESCRIPTOR_MOVE;DESCRIPTOR_PREFIX_OR_NAMESPACE;VERIFY_HASH_VALUES</DefineConstants>
<PackageId>XmlDiffPatch</PackageId>
<Copyright>Copyright © Microsoft</Copyright>
<Company>Microsoft Corporation</Company>
<Authors>Chris Lovett</Authors>
<Product>XmlDiffPatch 1.0</Product>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand All @@ -15,22 +14,14 @@
<PackageTags>xml;xml notepad;xmldiff</PackageTags>
<AssemblyName>XmlDiffPatch</AssemblyName>
<RootNamespace>Microsoft.XmlDiffPatch</RootNamespace>
<AssemblyOriginatorKeyFile>$(MyKeyFile)</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<SignAssembly>false</SignAssembly>
<DelaySign>false</DelaySign>
<Description>A library that compares XML files</Description>
<Version>1.0.4</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.1|AnyCPU'">
<DocumentationFile>$(ProjectDir)\XmlDiffPatch.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework) == net452 or $(TargetFramework) == net46 or $(TargetFramework) == net47 or $(TargetFramework) == net48">
<AssemblyOriginatorKeyFile>$(MyKeyFile)</AssemblyOriginatorKeyFile>
<SignManifests Condition="'$(AssemblyOriginatorKeyFile)'!=''">true</SignManifests>
<SignAssembly Condition="'$(AssemblyOriginatorKeyFile)'!=''">true</SignAssembly>
<ManifestTimestampUrl>http://timestamp.sectigo.com</ManifestTimestampUrl>
</PropertyGroup>
<ItemGroup>
<None Include="icon.png">
<Pack>True</Pack>
Expand Down
4 changes: 2 additions & 2 deletions src/XmlDiffView/XmlDiff.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<package >
<metadata>
<id>LovettSoftware.XmlDiff</id>
<version>1.0.4</version>
<version>1.0.5</version>
<authors>Chris Lovett</authors>
<description>A library that compares and merges XML files.</description>
<projectUrl>https://github.com/lovettchris/xmldiff</projectUrl>
Expand Down Expand Up @@ -40,7 +40,7 @@
<file src="..\XmlDiff\XmlDiffPatch.xml" target="lib\netcoreapp3.1" />
<file src=".\XmlDiffPatch.View.xml" target="lib\netcoreapp3.1" />
<file src=".\bin\Release\netcoreapp3.1\*.json" target="lib\netcoreapp3.1" />
<!-- .NET Framework 5.0 -->
<!-- .NET Framework 6.0 -->
<file src=".\bin\Release\net6.0\*.dll" target="lib\net6.0" />
<file src="..\XmlDiff\XmlDiffPatch.xml" target="lib\net6.0" />
<file src=".\XmlDiffPatch.View.xml" target="lib\net6.0" />
Expand Down
13 changes: 2 additions & 11 deletions src/XmlDiffView/XmlDiffView.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<Import Project="../Common/version.props" />
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netstandard2.1;net452;net46;net47;net48;netcoreapp3.1;net6.0</TargetFrameworks>
<PackageId>XmlDiffView</PackageId>
<Copyright>Copyright © Microsoft</Copyright>
<Company>Lovett Software</Company>
<Authors>Chris Lovett</Authors>
<Product>XmlDiffView 1.0</Product>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand All @@ -14,22 +13,14 @@
<PackageTags>xml;xmldiff</PackageTags>
<AssemblyName>XmlDiffPatch.View</AssemblyName>
<RootNamespace>Microsoft.XmlDiffPatch.View</RootNamespace>
<AssemblyOriginatorKeyFile>$(MyKeyFile)</AssemblyOriginatorKeyFile>
<SignAssembly>true</SignAssembly>
<SignAssembly>false</SignAssembly>
<Description>Displays the results of an XML file comparison</Description>
<DelaySign>false</DelaySign>
<Version>1.0.4</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)|$(Platform)'=='Release|netstandard2.0|AnyCPU'">
<DocumentationFile>$(ProjectDir)\XmlDiffPatch.View.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition="$(TargetFramework) == net452 or $(TargetFramework) == net46 or $(TargetFramework) == net47 or $(TargetFramework) == net48">
<AssemblyOriginatorKeyFile>$(MyKeyFile)</AssemblyOriginatorKeyFile>
<SignManifests Condition="'$(AssemblyOriginatorKeyFile)'!=''">true</SignManifests>
<SignAssembly Condition="'$(AssemblyOriginatorKeyFile)'!=''">true</SignAssembly>
<ManifestTimestampUrl>http://timestamp.sectigo.com</ManifestTimestampUrl>
</PropertyGroup>

<ItemGroup>
<None Include="icon.png">
Expand Down

0 comments on commit 12aad29

Please sign in to comment.