Skip to content

Commit

Permalink
Build script - tweaks and fixes
Browse files Browse the repository at this point in the history
Hit this issue...
https://docs.microsoft.com/en-us/dotnet/core/tools/sdk-errors/netsdk1005

Replaced the old "vswhere.exe" and MSBuild.exe calls with `dotnet` cli.

Removed the Umbraco package XML manifest - no longer needed.
  • Loading branch information
leekelleher committed Jul 8, 2021
1 parent 9ef9b5e commit 833ca9f
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 126 deletions.
5 changes: 2 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@ artifacts/
build/assets/
src/packages/*/**
/tools/*.exe
/build/__umb/*
/build/__nuget/*
/build/build-push.ps1
/build/build-push-nuget.ps1
/build/build-push-umb.ps1
6 changes: 0 additions & 6 deletions build/build-assets.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ if (Test-Path -Path $targetFolder) {
Remove-Item -Recurse -Force $targetFolder;
}

# Copy DLL / PDB
$binFolder = "${targetFolder}\bin\Debug\net5.0";

if (!(Test-Path -Path $binFolder)) {New-Item -Path $binFolder -Type Directory;}
Copy-Item -Path "${TargetDir}${ProjectName}.*" -Destination $binFolder;

# Copy package front-end files assets
$pluginFolder = "${targetFolder}\App_Plugins\Contentment\";
if (!(Test-Path -Path $pluginFolder)) {New-Item -Path $pluginFolder -Type Directory;}
Expand Down
97 changes: 22 additions & 75 deletions build/build-pkgs.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@

$nugetPackageId = 'Our.Umbraco.Community.Contentment';
$projectNamespace = 'Umbraco.Community.Contentment';
$packageName = 'Contentment';
$nugetTitle = "${packageName} for Umbraco";
$packageDescription = "${packageName}, a collection of components for Umbraco 8.";
$nugetTitle = "Contentment for Umbraco";
$packageDescription = "Contentment, a collection of components for Umbraco.";
$packageUrl = 'https://github.com/leekelleher/umbraco-contentment';
$iconUrl = 'https://raw.githubusercontent.com/leekelleher/umbraco-contentment/master/docs/assets/img/logo.png';
$licenseName = 'Mozilla Public License Version 2.0';
$licenseUrl = 'https://mozilla.org/MPL/2.0/';
$authorName = 'Lee Kelleher';
$authorUrl = 'https://leekelleher.com/';
$minUmbracoVersion = 8,14,0;
$copyright = "Copyright " + [char]0x00A9 + " " + (Get-Date).year + " $authorName";
$minUmbracoVersion = "9.0.0-rc001";
$copyright = "" + [char]0x00A9 + " " + (Get-Date).year + " $authorName";
$tags = "umbraco";

$rootFolder = (Get-Item($MyInvocation.MyCommand.Path)).Directory.Parent.FullName;
Expand All @@ -32,84 +27,36 @@ $csprojXml = [xml](Get-Content -Path "${srcFolder}\${projectNamespace}\${project
$version = $csprojXml.Project.PropertyGroup.Version;
Write-Host "Package version: $version";

# Build the VS project

# Ensure NuGet.exe
$nuget_exe = "${rootFolder}\tools\nuget.exe";
If (-NOT(Test-Path -Path $nuget_exe)) {
Write-Host "Retrieving nuget.exe...";
Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $nuget_exe;
}

# vswhere.exe is part of VS2017 (v15.2)+
$vswhere_exe = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe";

$msbuild_exe = & "$vswhere_exe" -Latest -Requires Microsoft.Component.MSBuild -Find MSBuild\**\Bin\MSBuild.exe | Select-Object -First 1
if (-NOT(Test-Path $msbuild_exe)) {
throw 'MSBuild not found!';
}

Write-Host 'Restoring NuGet packages...';
& $nuget_exe restore "${srcFolder}\${projectNamespace}.sln";
# Build the VS project
Write-Host 'Cleaning Visual Studio solution.';
& dotnet clean "${srcFolder}\${projectNamespace}.sln";

Write-Host 'Compiling Visual Studio solution.';
& $msbuild_exe "${srcFolder}\${projectNamespace}.sln" /p:Configuration=Release
& dotnet build "${srcFolder}\${projectNamespace}.sln" --configuration Release
if (-NOT $?) {
throw 'The MSBuild process returned an error code.';
throw 'The dotnet CLI returned an error code.';
}


# Populate the Umbraco package manifest

$umbFolder = Join-Path -Path $buildFolder -ChildPath "__umb";
if (!(Test-Path -Path $umbFolder)) {New-Item -Path $umbFolder -Type Directory;}

$umbracoManifest = Join-Path -Path $buildFolder -ChildPath "manifest-umbraco.xml";
$umbracoPackageXml = [xml](Get-Content $umbracoManifest);
$umbracoPackageXml.umbPackage.info.package.version = "$($version)";
$umbracoPackageXml.umbPackage.info.package.name = $packageName;
$umbracoPackageXml.umbPackage.info.package.iconUrl = $iconUrl;
$umbracoPackageXml.umbPackage.info.package.license.set_InnerText($licenseName);
$umbracoPackageXml.umbPackage.info.package.license.url = $licenseUrl;
$umbracoPackageXml.umbPackage.info.package.url = $packageUrl;
$umbracoPackageXml.umbPackage.info.package.requirements.major = "$($minUmbracoVersion[0])";
$umbracoPackageXml.umbPackage.info.package.requirements.minor = "$($minUmbracoVersion[1])";
$umbracoPackageXml.umbPackage.info.package.requirements.patch = "$($minUmbracoVersion[2])";
$umbracoPackageXml.umbPackage.info.author.name = $authorName;
$umbracoPackageXml.umbPackage.info.author.website = $authorUrl;
$umbracoPackageXml.umbPackage.info.readme."#cdata-section" = $packageDescription;

$filesXml = $umbracoPackageXml.CreateElement("files");
# Copy DLL to assets folder
$binFolder = "${assetsFolder}\bin";
if (!(Test-Path -Path $binFolder)) {New-Item -Path $binFolder -Type Directory;}
Copy-Item -Path "${srcFolder}\${projectNamespace}\bin\Release\net5.0\${projectNamespace}.dll" -Destination $binFolder;

$assetFiles = Get-ChildItem -Path $assetsFolder -File -Recurse;
foreach($assetFile in $assetFiles){

$hash = Get-FileHash -Path $assetFile.FullName -Algorithm MD5;
$guid = $hash.Hash.ToLower() + $assetFile.Extension;
$orgPath = "~" + $assetFile.Directory.FullName.Replace($assetsFolder, "").Replace("\", "/");

$fileXml = $umbracoPackageXml.CreateElement("file");
$fileXml.set_InnerXML("<guid>${guid}</guid><orgPath>${orgPath}</orgPath><orgName>$($assetFile.Name)</orgName>");
$filesXml.AppendChild($fileXml);

Copy-Item -Path $assetFile.FullName -Destination "${umbFolder}\${guid}";
}

$umbracoPackageXml.umbPackage.ReplaceChild($filesXml, $umbracoPackageXml.SelectSingleNode("/umbPackage/files")) | Out-Null;
$umbracoPackageXml.Save("${umbFolder}\package.xml");

# Ensure the artifacts folder
$artifactsFolder = Join-Path -Path $rootFolder -ChildPath "artifacts";
if (!(Test-Path -Path $artifactsFolder)) {New-Item -Path $artifactsFolder -Type Directory;}
Compress-Archive -Path "${umbFolder}\*" -DestinationPath "${artifactsFolder}\Contentment_$version.zip" -Force;

# Ensure NuGet.exe
$nuget_exe = "${rootFolder}\tools\nuget.exe";
If (-NOT(Test-Path -Path $nuget_exe)) {
Write-Host "Retrieving nuget.exe...";
Invoke-WebRequest "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe" -OutFile $nuget_exe;
}

# Populate the NuGet package manifest

Copy-Item -Path "${rootFolder}\docs\assets\img\logo.png" -Destination "${assetsFolder}\icon.png";
& $nuget_exe pack "${buildFolder}\manifest-nuget-core.nuspec" -BasePath $assetsFolder -OutputDirectory $artifactsFolder -Version "$version" -Properties "id=$nugetPackageId;version=$version;title=$nugetTitle;authors=$authorName;owners=$authorName;projectUrl=$packageUrl;requireLicenseAcceptance=false;description=$packageDescription;copyright=$copyright;license=MPL-2.0;language=en;tags=$tags;minUmbracoVersion=$($minUmbracoVersion[0]).$($minUmbracoVersion[1]).$($minUmbracoVersion[2]);repositoryUrl=$packageUrl;"
& $nuget_exe pack "${buildFolder}\manifest-nuget-web.nuspec" -BasePath $assetsFolder -OutputDirectory $artifactsFolder -Version "$version" -Properties "id=$nugetPackageId;version=$version;title=$nugetTitle;authors=$authorName;owners=$authorName;projectUrl=$packageUrl;requireLicenseAcceptance=false;description=$packageDescription;copyright=$copyright;license=MPL-2.0;language=en;tags=$tags;minUmbracoVersion=$($minUmbracoVersion[0]).$($minUmbracoVersion[1]).$($minUmbracoVersion[2]);repositoryUrl=$packageUrl;"


# Tidy up folders
Remove-Item -Recurse -Force $umbFolder;

& $nuget_exe pack "${buildFolder}\manifest-nuget-core.nuspec" -BasePath $assetsFolder -OutputDirectory $artifactsFolder -Version "$version" -Properties "id=$nugetPackageId;version=$version;title=$nugetTitle;authors=$authorName;owners=$authorName;projectUrl=$packageUrl;requireLicenseAcceptance=false;description=$packageDescription;copyright=$copyright;license=MPL-2.0;language=en;tags=$tags;minUmbracoVersion=$minUmbracoVersion;repositoryUrl=$packageUrl;"
& $nuget_exe pack "${buildFolder}\manifest-nuget-web.nuspec" -BasePath $assetsFolder -OutputDirectory $artifactsFolder -Version "$version" -Properties "id=$nugetPackageId;version=$version;title=$nugetTitle;authors=$authorName;owners=$authorName;projectUrl=$packageUrl;requireLicenseAcceptance=false;description=$packageDescription;copyright=$copyright;license=MPL-2.0;language=en;tags=$tags;minUmbracoVersion=$minUmbracoVersion;repositoryUrl=$packageUrl;"
8 changes: 4 additions & 4 deletions build/manifest-nuget-core.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
<tags>$tags$</tags>
<repository type="git" url="$repositoryUrl$" />
<dependencies>
<group targetFramework="net472">
<dependency id="UmbracoCms.Core" version="[$minUmbracoVersion$, 9.0.0)" />
<dependency id="UmbracoCms.Web" version="[$minUmbracoVersion$, 9.0.0)" />
<group targetFramework="net5.0">
<dependency id="UmbracoCms.Core" version="[$minUmbracoVersion$, 10.0.0)" />
<dependency id="UmbracoCms.Web" version="[$minUmbracoVersion$, 10.0.0)" />
</group>
</dependencies>
</metadata>
<files>
<file src="bin\*.*" target="lib\net472" />
<file src="bin\*.*" target="lib\net5.0" />
<file src="icon.png" target="" />
</files>
</package>
37 changes: 0 additions & 37 deletions build/manifest-umbraco.xml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<TargetFrameworks>net5.0</TargetFrameworks>
<Product>Umbraco.Community.Contentment</Product>
<PackageId>Our.Umbraco.Community.Contentment</PackageId>
<Title>Contentment for Umbraco</Title>
Expand Down

0 comments on commit 833ca9f

Please sign in to comment.