Skip to content

Commit

Permalink
Generalise local and CI build experiences (#76)
Browse files Browse the repository at this point in the history
The app can be build with "dotnet" without custom scripts.
Packaging and publishing moved into MSBuild targets.
  • Loading branch information
RussKie authored Jul 31, 2024
1 parent 013e2be commit daaf7af
Show file tree
Hide file tree
Showing 14 changed files with 267 additions and 180 deletions.
13 changes: 13 additions & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<LangVersion>latest</LangVersion>
<NoWarn>$(NoWarn);1573;1591;1712</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
<PackageManagerUIRuntimeIdentifier>win-x86</PackageManagerUIRuntimeIdentifier>
</PropertyGroup>

<PropertyGroup>
Expand All @@ -19,4 +21,15 @@
<PackageVersion>0.0.0.1</PackageVersion>
</PropertyGroup>

<!-- Repo layout -->
<PropertyGroup>
<RepoRoot Condition="'$(RepoRoot)' == ''">$([MSBuild]::NormalizeDirectory('$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildProjectDirectory), 'appveyor.yml'))'))</RepoRoot>

<ArtifactsDir Condition="'$(ArtifactsDir)' == ''">$([MSBuild]::NormalizeDirectory('$(RepoRoot)', 'artifacts', '$(Configuration)'))</ArtifactsDir>
<ArtifactsObjDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'obj'))</ArtifactsObjDir>
<ArtifactsBinDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'bin'))</ArtifactsBinDir>
<ArtifactsTestResultsDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'TestResults'))</ArtifactsTestResultsDir>
<ArtifactsTmpDir>$([MSBuild]::NormalizeDirectory('$(ArtifactsDir)', 'tmp'))</ArtifactsTmpDir>
</PropertyGroup>

</Project>
2 changes: 0 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
<Project>

<Sdk Name="Microsoft.Build.CentralPackageVersions" Version="2.1.3" />

</Project>
29 changes: 29 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<PropertyGroup>
<!-- To support GitExtensions.Extensibility 0.3.*, see https://learn.microsoft.com/en-us/nuget/reference/errors-and-warnings/nu1011 -->
<CentralPackageFloatingVersionsEnabled>true</CentralPackageFloatingVersionsEnabled>
</PropertyGroup>

<!-- Solution dependencies -->
<ItemGroup>
<PackageVersion Include="Microsoft.VisualStudio.Composition" Version="17.2.41" />
<PackageVersion Include="GitExtensions.Extensibility" Version="0.3.*" />
<PackageVersion Include="Neptuo" Version="6.0.2" />
<PackageVersion Include="Neptuo.Exceptions" Version="1.2.2" />
<PackageVersion Include="Neptuo.Observables" Version="2.1.1" />
<PackageVersion Include="NuGet.PackageManagement" Version="6.8.0" />
<PackageVersion Include="System.Resources.Extensions" Version="8.0.0" />
</ItemGroup>

<!-- Test-related -->
<ItemGroup>
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageVersion Include="Moq" Version="4.18.2" />
<PackageVersion Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageVersion Include="MSTest.TestFramework" Version="2.2.10" />
<PackageVersion Include="Appveyor.TestLogger" Version="2.0.0" />
</ItemGroup>

</Project>
5 changes: 5 additions & 0 deletions GitExtensions.PluginManager.sln
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
VisualStudioVersion = 17.5.33130.490
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GitExtensions.PluginManager", "src\GitExtensions.PluginManager\GitExtensions.PluginManager.csproj", "{4EB0566E-6D4F-43AF-AA97-2A15ABB66787}"
ProjectSection(ProjectDependencies) = postProject
{3B5E3720-B3CB-4A12-B2D4-6BCB6BE78FF1} = {3B5E3720-B3CB-4A12-B2D4-6BCB6BE78FF1}
{B302D166-37CE-439D-8AE1-0CCB80BAD332} = {B302D166-37CE-439D-8AE1-0CCB80BAD332}
{E7AD4376-D8B1-469D-A2E3-38059A5EB152} = {E7AD4376-D8B1-469D-A2E3-38059A5EB152}
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PackageManager.UI", "src\PackageManager.UI\PackageManager.UI.csproj", "{6F4FA02A-B061-4607-925E-27B122DE60BC}"
EndProject
Expand Down
22 changes: 0 additions & 22 deletions Packages.props

This file was deleted.

77 changes: 60 additions & 17 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#---------------------------------#
# general configuration #
#---------------------------------#

# version format
version: 3.0.0.{build}

matrix:
fast_finish: true

# Build worker image (VM template)
image:
- Visual Studio 2022

# version suffix, if any (e.g. '-RC1', '-beta' otherwise '')
environment:
version_suffix: ''
Expand All @@ -13,17 +16,16 @@ environment:
# Disable the .NET first time experience to skip caching NuGet packages and speed up the build.
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true


# Do not build on tags (GitHub and BitBucket)
skip_tags: true

#---------------------------------#
# environment configuration #
#---------------------------------#

# Build worker image (VM template)
image:
- Visual Studio 2022
# Build settings, not to be confused with "before_build" and "after_build".
# "project" is relative to the original build directory and not influenced by directory changes in "before_build".
build:
# enable MSBuild parallel builds
parallel: true
# MSBuild verbosity level
verbosity: minimal

# enable patching of Directory.Build.props
dotnet_csproj:
Expand All @@ -39,21 +41,62 @@ dotnet_csproj:
# build configuration #
#---------------------------------#

install:
- ps: |
# Install the required .NET SDK
Invoke-WebRequest "https://dot.net/v1/dotnet-install.ps1" -OutFile "./dotnet-install.ps1"
./dotnet-install.ps1 -Channel LTS -InstallDir 'C:\Program Files\dotnet'
# Remove the script so it doesn't "pollute" the build
Remove-Item -Path .\dotnet-install.ps1
build_script:
- ps: .\tools\Prepare-Release.ps1
- ps: |
dotnet restore --verbosity q --nologo /bl:.\artifacts\logs\restore.binlog
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
- ps: |
dotnet build -c Release --verbosity q --nologo /bl:.\artifacts\logs\build.binlog
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
- ps: |
dotnet publish --configuration Release --verbosity q -bl:.\artifacts\logs\publish.binlog
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
#---------------------------------#
# tests configuration #
#---------------------------------#

test_script:
- ps: .\tools\Run-Tests.ps1
- ps: |
dotnet test -c Release --no-restore --no-build --nologo --verbosity q --test-adapter-path:. --logger:Appveyor --logger:trx /bl:.\artifacts\logs\tests.binlog
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
#---------------------------------#
# artifacts configuration #
#---------------------------------#

artifacts:
- path: .\GitExtensions.PluginManager.*.zip
- path: .\GitExtensions.PluginManager.*.nupkg
- path: .\*.binlog
- path: .\artifacts\GitExtensions.PluginManager.*.zip
- path: .\artifacts\GitExtensions.PluginManager.*.nupkg
- path: .\artifacts\logs\*.binlog


# on build failure
on_failure:
- ps: |
Get-ChildItem -recurse artifacts\Release\TestsResults\*.trx -ErrorAction SilentlyContinue `
| ForEach-Object {
Push-AppveyorArtifact "$_"
}
- ps: |
Get-ChildItem -recurse artifacts\Release\TestsResults\*.trx | `
ForEach-Object {
$file = $_.FullName.Replace('[', '``[').Replace(']', '``]')
#Write-Output "Processing $file"
[xml]$xml = Get-Content -Path $file
$xml.TestRun.Results.UnitTestResult | Where-Object outcome -eq 'Failed' | ForEach-Object {
$errorMessage = "$($_.Output.ErrorInfo.Message)`r`n$($_.Output.ErrorInfo.StackTrace)`r`n"
Write-Host $errorMessage -ForegroundColor Red
}
}
41 changes: 5 additions & 36 deletions src/GitExtensions.PluginManager/GitExtensions.PluginManager.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(MSBuildProjectDirectory)\Project.Publish.targets" />

<PropertyGroup>
<UseWindowsForms>true</UseWindowsForms>
Expand All @@ -9,12 +10,7 @@
<RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
<NuspecFile>$(MSBuildThisFileDirectory)$(MSBuildProjectName).nuspec</NuspecFile>
<NoWarn>1701;1702;NU5100;NU5101;NU5103;NU5128</NoWarn>
</PropertyGroup>

<PropertyGroup>
<PackageManagerTargetPath>PackageManager\PackageManager.UI.exe</PackageManagerTargetPath>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageManagerSourcePath>..\PackageManager.UI\bin\$(Configuration)\$(TargetFramework)\publish\PackageManager.UI.exe</PackageManagerSourcePath>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
Expand All @@ -37,7 +33,8 @@
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\PackageManager.UI\PackageManager.UI.csproj" ReferenceOutputAssembly="false" />
<ProjectReference Include="..\PackageManager.UI\PackageManager.UI.csproj"
ReferenceOutputAssembly="false" />
</ItemGroup>

<ItemGroup>
Expand All @@ -51,38 +48,10 @@
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

<Target Name="CopyPackageManager" AfterTargets="PostBuildEvent">
<Copy SourceFiles="$(PackageManagerSourcePath)" DestinationFiles="$(TargetDir)$(PackageManagerTargetPath)" />
<Copy SourceFiles="$(PackageManagerSourcePath)" DestinationFiles="$(GitExtensionsPluginsPath)\$(ProjectName)\$(PackageManagerTargetPath)" />
</Target>

<Target Name="PreClean" BeforeTargets="Clean">
<Message Text="Deleting PackageManager" Importance="high" />
<Delete Files="$(TargetDir)$(PackageManagerTargetPath)" ContinueOnError="true" />
</Target>

<Target Name="SetPackageProperties" BeforeTargets="GenerateNuspec">
<PropertyGroup>
<NuspecProperties>
id=$(PackageId);
version=$(PackageVersion);
configuration=$(Configuration);
tags=$(PackageTags.Replace(';',' '));
projectUrl=$(PackageProjectUrl);
iconUrl=$(PackageIconUrl);
repositoryUrl=$(RepositoryUrl);
repositoryType=$(RepositoryType);
repositoryCommit=$(RepositoryCommit);
author=$(Authors);
copyright=$(Copyright);
description=$(Description);
targetDir=$(TargetDir);
</NuspecProperties>
</PropertyGroup>
</Target>

<Target Name="Zip" AfterTargets="Pack">
<Exec Command="powershell -ExecutionPolicy Unrestricted $(MSBuildProjectDirectory)\..\..\tools\Zip-GitExtensionsPlugin.ps1 -Version $(PackageVersion) -Configuration $(Configuration)" />
</Target>
</Project>
</Project>
110 changes: 110 additions & 0 deletions src/GitExtensions.PluginManager/Project.Publish.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<Project>
<PropertyGroup>
<_PackageManagerFolder>PackageManager</_PackageManagerFolder>
</PropertyGroup>

<!--
============================================================
_CopyPackageManager
Copy PackageManager.UI into GitExtensions.PluginManager so it can get packed and
to Git Extensions shared installation so we can test it locally
============================================================
-->
<Target Name="_CopyPackageManager">
<PropertyGroup>
<_PackageManagerSourcePath>$([MSBuild]::NormalizePath('$(RepoRoot)', 'src', 'PackageManager.UI', 'bin', '$(Configuration)', '$(TargetFramework)', '$(PackageManagerUIRuntimeIdentifier)', 'publish', 'PackageManager.UI.exe'))</_PackageManagerSourcePath>
<_PackageManagerTargetPath>$(_PackageManagerFolder)\PackageManager.UI.exe</_PackageManagerTargetPath>
</PropertyGroup>

<!-- Copying to we can pack it -->
<Copy SourceFiles="$(_PackageManagerSourcePath)"
DestinationFiles="$(TargetDir)$(_PackageManagerTargetPath)" />

<!-- Copying to Git Extensions shared installation so we can test it locally -->
<Copy SourceFiles="$(_PackageManagerSourcePath)"
DestinationFiles="$(GitExtensionsPluginsPath)\$(ProjectName)\$(_PackageManagerTargetPath)" />
</Target>

<!--
============================================================
_SetPackageProperties
Update nuspec properties.
============================================================
-->
<Target Name="_SetPackageProperties" BeforeTargets="GenerateNuspec">
<PropertyGroup>
<NuspecProperties>
id=$(PackageId);
version=$(PackageVersion);
configuration=$(Configuration);
tags=$(PackageTags.Replace(';',' '));
projectUrl=$(PackageProjectUrl);
iconUrl=$(PackageIconUrl);
repositoryUrl=$(RepositoryUrl);
repositoryType=$(RepositoryType);
repositoryCommit=$(RepositoryCommit);
author=$(Authors);
copyright=$(Copyright);
description=$(Description);
targetDir=$(TargetDir);
</NuspecProperties>
</PropertyGroup>
</Target>

<!--
============================================================
_OverrideGetAbsoluteOutputPathsForPack
Override PackageOutputAbsolutePath to output the nupkg in artifacts folder instead of bin.
============================================================
-->
<Target Name="_OverrideGetAbsoluteOutputPathsForPack" AfterTargets="_GetAbsoluteOutputPathsForPack">
<PropertyGroup>
<!-- Set the nupkg output path, used by GenerateNuspec targets, PackTask task -->
<PackageOutputAbsolutePath>$([MSBuild]::NormalizePath('$(ArtifactsDir)', '..'))</PackageOutputAbsolutePath>
</PropertyGroup>
</Target>

<!--
============================================================
CreatePortable
Creates a portable archive.
============================================================
-->
<Target Name="CreatePortable"
AfterTargets="Publish"
DependsOnTargets="_CopyPackageManager;Pack">
<PropertyGroup>
<_PublishPortableFileName>GitExtensions.PluginManager.$(PackageVersion).zip</_PublishPortableFileName>
<_PublishPortablePath>$([MSBuild]::NormalizePath('$(ArtifactsDir)', '..', '$(_PublishPortableFileName)'))</_PublishPortablePath>

<!-- We want to archive the whole publish folder, so get one level up -->
<_PublishedPath>$([MSBuild]::NormalizeDirectory('$(PublishDir)'))</_PublishedPath>
</PropertyGroup>
<!-- 1. Copy GitExtensions.PluginManager.dll and PackageManager\PackageManager.UI.exe files -->
<Copy
SourceFiles="$(TargetPath)"
DestinationFolder="$(ArtifactsTmpDir)"
ContinueOnError="ErrorAndStop"
/>
<ItemGroup>
<_ZipContent Include="$([MSBuild]::NormalizePath('$(TargetDir)', '$(_PackageManagerFolder)'))\*.*" />
</ItemGroup>
<Copy
SourceFiles="@(_ZipContent)"
DestinationFolder="$(ArtifactsTmpDir)$(_PackageManagerFolder)\%(RecursiveDir)"
ContinueOnError="ErrorAndStop"
/>

<!-- 2. Create a portable archive -->
<ZipDirectory
SourceDirectory="$(ArtifactsTmpDir)"
DestinationFile="$(_PublishPortablePath)"
Overwrite="true"
ContinueOnError="ErrorAndStop"
/>
</Target>
</Project>
2 changes: 1 addition & 1 deletion src/PackageManager.UI/PackageManager.UI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<PublishSingleFile>true</PublishSingleFile>
<SelfContained>false</SelfContained>
<RuntimeIdentifier>win-x86</RuntimeIdentifier>
<RuntimeIdentifier>$(PackageManagerUIRuntimeIdentifier)</RuntimeIdentifier>
<PublishReadyToRun>true</PublishReadyToRun>
</PropertyGroup>

Expand Down
Loading

0 comments on commit daaf7af

Please sign in to comment.