Last active
February 17, 2020 15:06
-
-
Save fliedonion/e920d5284d884e569d68b31502ebc126 to your computer and use it in GitHub Desktop.
appveyor.yml for build library
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# AppVeyor.yml for Zipped files to XCopy Deploy. | |
# - Require VS2013 ($env:MSBUILD_EXE) | |
# - Require 7Zip ($env:szip) | |
# - "C:\opt\nuget3.4\appveyor_nugetconfig\nuget.config" | |
# - C:\opt\nuget3.4\nget.exe | |
# version: 1.0.{build} | |
# 必要に応じてAssemblyInfoパッチなども行う。このymlを共通で使うならここでバージョンしない方が良いと思う。 | |
configuration: Release | |
# なんか不要なスペースが末尾についてしまう。大したコマンドでもないので、after_buildはpowershellあたりでやるといいのかも。 | |
# beforefilter.xmlで<DocumentationFile></DocumentationFile> も設定しようかと思ったがこのタイミングだと $(TargetName) とか取れないのでやめた | |
# BeforeTargetが CoreCompileの Targetを作ればいけるかもしれない。 | |
# MsBuild v15 以降なら https://stackoverflow.com/a/53284172 が参考に。 | |
# 環境変数 `$env:FoEnvSLNTITLE` `$env:FoEnvSLN` はここで定義せずにUIでプロジェクトの環境変数かinitで定義しておけば使いまわせる。 | |
# To see all predefined msbuild targets, see: https://docs.microsoft.com/ja-jp/visualstudio/msbuild/msbuild-targets?view=vs-2019 | |
## Controlable Variables for this build setting. | |
# | |
# $env:FoEnvSLN | |
# specify relative path to target solution file. | |
# if multiple solution file found, first found one will be used. | |
# ex) ".\src\AppVeyorSimpleExeExpr.sln" | |
# default: "*.sln" | |
# $env:FoEnvRemoveDependencies | |
# "0" or "1". non zero integer means True. "0" means False. | |
# Remove dependency files from artifact. remove also project dependencies. | |
# default: "0" | |
# $env:FoEnvPROJECTS | |
# semi-colon separated Project names. comma also allowed as separated character. | |
# space will be trimmed. empty | |
# more correctly this is a build target. | |
# note: "Clean" always run as first build target, so you don't need specify Clean. | |
# note: Replace some sign to underscore. that is MsBuild Spec. | |
# ex) "ClassLibrary1; SecondApps, " | |
# default: Rebuild | |
# $env:FoEnvMSBUILD_EXE | |
# default: "C:\Program Files (x86)\MSBuild\12.0\Bin\amd64\MSBuild.exe" | |
# $env:FoEnvConfiguration | |
# "Release", "Debug" or "Default". | |
# if "Default" is specified, use solution or project default. (not override configuration setting) | |
# default: Release | |
# $env:FoEnvPlatform | |
# "Any CPU", "x64", "x86", ..., or "Default". | |
# if "Default" is specified, use solution or project default. (not override platform setting) | |
# default: Default | |
# $env:FoEnvMsBuildLogLevel | |
# default: m | |
# $env:FoEnvNuget_EXE | |
# set fullpath to nuget.exe. this will be used for restore packages. | |
# if you don't want to restore, please set empty string. | |
# default: "C:\opt\nuget3.4\nuget.exe" | |
# $env:FoEnvNugetConfig | |
# set fullpath to custom nuget.config if you want use that. | |
# this file will be copy to Solution File Directory. | |
# if you don't want to use any extra file, please set empty string. | |
# default: "C:\opt\nuget3.4\appveyor_nugetconfig" | |
# note: you may find nuget.config for your user account in `C:\Users\<UserName>\AppData\Roaming\NuGet` | |
## log level for this build setting. | |
# $env:FoLogInfo=1 : print info log | |
# $env:FoLogVerbose=1 : print info/verbose log | |
# $env:FoLogDebug=1 : print info/verbose/debug log | |
# $env:FoLogNone=1 : don't print log | |
test: | |
assemblies: | |
only: | |
- none.dll | |
before_build: | |
- ps: >- | |
# variables for Testing | |
$env:FoLogVerbose=1 | |
$env:FoEnvSLN=".\src\AppVeyorSimpleExeExpr.sln" | |
# $env:FoEnvPROJECTS="AppVeyorSimpleExeExpr ; SecondApps, " | |
# $env:FoEnvRemoveDependencies = "1" | |
# $env:FoEnvMsBuildLogLevel = "d" | |
############### | |
# Setup logging | |
function folog($s, $prefix) { Write-Host $( [string]::Format('{1} {0}', $s, $prefix) ); } | |
function foilog($s) { if ($FoLogLevel -ge 1) { folog $s '[Info ]:'; } } # ilog stands for info log. | |
function fovlog($s) { if ($FoLogLevel -ge 2) { folog $s '[Verbose]:'; } } # vlog stands for verbose log. | |
function fodlog($s) { if ($FoLogLevel -ge 4) { folog $s '[Debug ]:'; } } # dlog stands for debug log. | |
$FoLogLevel=1; | |
if ($env:FoLogInfo) { $FoLogLevel += 1 }; | |
if ($env:FoLogVerbose) { $FoLogLevel += 2 }; | |
if ($env:FoLogDebug) { $FoLogLevel += 4 }; | |
if ($env:FoLogNone) { $FoLogLevel = 0 }; | |
fovlog "Log Level is $FoLogLevel" | |
# Remove Dependencies Value | |
[bool]$FoRemoveDependencies=[int]$("0" + $env:FoEnvRemoveDependencies) | |
# apply custom msbuild | |
$env:MSBUILD_EXE="C:\Program Files (x86)\MSBuild\12.0\Bin\amd64\MSBuild.exe" | |
if ($env:FoEnvMSBUILD_EXE) { $env:MSBUILD_EXE=$env:FoEnvMSBUILD_EXE } | |
fovlog "MsBuild is $env:MSBUILD_EXE" | |
# apply nuget configuration | |
$env:FoEnvNuget_EXE="C:\opt\nuget3.4\nuget.exe" | |
$env:FoEnvNugetConfig="C:\opt\nuget3.4\appveyor_nugetconfig\nuget.config" | |
# apply configuration | |
$FoBuildConfigParam="/p:Configuration=$env:configuration" | |
if ($env:FoEnvConfiguration) { | |
$FoBuildConfigParam=[string]::Format('/p:Configuration="{0}"', $env:FoEnvConfiguration); | |
if ( "$env:FoEnvConfiguration" -eq "Default" ) { | |
$FoBuildConfigParam="/p:Configuration=$env:configuration" | |
} | |
} | |
fovlog "Configuration parameter is $FoBuildConfigParam" | |
# apply platform | |
$FoBuildPlatformParam="" | |
if ($env:FoEnvPlatform) { | |
$FoBuildPlatformParam=[string]::Format('/p:Platform="{0}"', $env:FoEnvPlatform); | |
if ( "$env:FoEnvPlatform" -eq "Default" ) { | |
$FoBuildPlatformParam="" | |
} | |
} | |
fovlog "Platform parameter is $FoBuildPlatformParam" | |
# apply msbuild log level | |
$FoMsBuildLogLevel='/v:m' | |
if ($env:FoEnvMsBuildLogLevel) { | |
$FoMsBuildLogLevel=[string]::Format('/v:{0}', $env:FoEnvMsBuildLogLevel); | |
} | |
fovlog "MsBuild Log verbosity is $FoMsBuildLogLevel" | |
# Find Solution file. | |
if ( ([string]$env:FoEnvSLN).Trim() -eq "" ) { $env:FoEnvSLN = '*.sln' } | |
if ( "$env:FoEnvSLN" -ne "" ) { | |
$FoSlnFile=( Get-Item "$env:FoEnvSLN" | Select -index 0 ) | |
if ( ! $FoSlnFile ) { Write-Error "$env:FoEnvSLN not found." ; $host.SetShouldExit( 1 ) } | |
# raise error Solution not found. | |
$env:FoEnvSLNPATH=$FoSlnFile[0].DirectoryName | |
$env:FoEnvSLNTITLE=$FoSlnFile[0].BaseName | |
} | |
foilog $( 'Found Solution is `' + $FoSlnFile + '`') | |
# Decide Buildtargets. | |
if ( ([string]$env:FoEnvPROJECTS).Trim() -eq "" ) { | |
# if project is not specified, fallback to Rebuild (all project) | |
$env:FoEnvPROJECTS = 'Rebuild'; | |
$FoIsProjNameFallbacked=1; | |
} | |
fovlog $( 'Target(s) are `' + $env:FoEnvPROJECTS + '`') | |
## format Buildtargets | |
$FoProjects_tmp=$env:FoEnvPROJECTS.split( (";", ",") ).foreach({$_.Trim()}).where({$_ -ne ""}) | |
$FoProjects=[string]::join(";", $FoProjects_tmp ) | |
$FoProjectsTarget=$FoProjects_tmp.foreach({$_.replace("'", "_") -replace '[%$@;.()]','_'}) | |
# replace some signs to underscore for -target switch. | |
if ( $FoProjects.Count -eq 0 ) { Write-Error 'Invalid $env:FoEnvPROJECTS value. maybe only semi-colon or comma.' ; $host.SetShouldExit( 1 ) } | |
fovlog $( 'Build Project(s) are `' + $FoProjects + '`') | |
$env:FoEnvProjectsToBuild=";$FoProjects;" # this value will be used in msbuild task. | |
fovlog $( '$env:FoEnvProjectsToBuild is `' + $env:FoEnvProjectsToBuild + '`') | |
if ($FoIsProjNameFallbacked) { $env:FoEnvProjectsToBuild="" } | |
### empty `$env:FoEnvProjectsToBuild` means no project will be excluded in msbuild task. | |
$env:FoEnvArtifactDirTitle="_veyor_artifacts" | |
$env:FoEnvArtifactFile="${env:FoEnvSLNTITLE}.zip" | |
- ps: >- | |
echo '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | |
<PropertyGroup> | |
<OutputPath>_veyor_out</OutputPath> | |
</PropertyGroup> | |
</Project> | |
' > beforefilter.xml | |
- ps: >- | |
echo '<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">' > afterfilter.xml | |
if ( $FoRemoveDependencies ) { | |
echo ' <!-- Remove Dependencies --> | |
<ItemDefinitionGroup> | |
<Reference> | |
<Private>False</Private> | |
</Reference> | |
<ProjectReference> | |
<Private>False</Private> | |
</ProjectReference> | |
</ItemDefinitionGroup> | |
' >> afterfilter.xml | |
} | |
$env:FoEnvEmpty="" # to avoid double single-quote complex. | |
echo ' <!-- Copy Files. this make easily create artifact after build --> | |
<Target Name="GetAssmeblyVersion" AfterTargets="Build"> | |
<GetAssemblyIdentity | |
AssemblyFiles="$(TargetPath)"> | |
<Output | |
TaskParameter="Assemblies" | |
ItemName="FoPropAssemblyIdentities"/> | |
</GetAssemblyIdentity> | |
<Message Text="FoEnvProjectsToBuild = $(FoEnvProjectsToBuild)" /> | |
<Message Text="MsBuildProjectName = $(MsBuildProjectName)" /> | |
<Message Text="Contains? = $(FoEnvProjectsToBuild.Contains( $(MsBuildProjectName) ))" /> | |
</Target> | |
<Target Name="CopyToVersionedFolder" AfterTargets="GetAssmeblyVersion" | |
Condition="''$(FoEnvProjectsToBuild)'' == ''$(FoEnvEmpty)'' Or $(FoEnvProjectsToBuild.Contains( $(MsBuildProjectName) ))"> | |
<ItemGroup> | |
<BuiltFiles Include="$(TargetDir)\*.*" /> | |
</ItemGroup> | |
<Copy SourceFiles="@(BuiltFiles)" | |
DestinationFolder="$(FoEnvSLNPATH)\$(FoEnvArtifactDirTitle)\$(TargetName)\%(FoPropAssemblyIdentities.Version)" /> | |
</Target> | |
' >> afterfilter.xml | |
echo '</Project>' >> afterfilter.xml | |
build_script: | |
- ps: >- | |
[string] $cwd = Get-Location | |
if ( "$env:FoEnvNugetConfig" -ne "" ) { | |
cp "$env:FoEnvNugetConfig" $cwd ; | |
} | |
if ( "$env:FoEnvNuget_EXE" -ne "" ) { | |
& $env:FoEnvNuget_EXE restore "$env:FoEnvSLN" | |
} | |
& $env:MSBUILD_EXE "$env:FoEnvSLN" $FoMsBuildLogLevel /t:"Clean;$FoProjects" | |
$FoBuildConfigParam $FoBuildPlatformParam | |
/p:DebugSymbols=false | |
/p:DebugType=None | |
/p:CustomBeforeMicrosoftCommonTargets="${cwd}\beforefilter.xml" | |
/p:CustomAfterMicrosoftCommonTargets="${cwd}\afterfilter.xml" | |
$_builtsignfile=Get-Date -Format "BUILT_yyyy-MM-dd_HH-mm-ss" | |
ls | |
new-item -type file "$env:FoEnvSLNPATH\$env:FoEnvArtifactDirTitle\$_builtsignfile" | |
after_build: | |
- ps: $env:szip="C:\Program Files\7-Zip\7z.exe" | |
- ps: '& $env:szip a "$env:FoEnvArtifactFile" "$env:FoEnvSLNPATH\$env:FoEnvArtifactDirTitle"' | |
artifacts: | |
- path: "%FoEnvArtifactFile%" | |
name: test build | |
type: zip |
beforefilter.xml はもう意味がないが、ここでプロジェクトプロパティを一部書き換えられるというサンプルとして残してる。
$_builtsignfile
もファイル名でビルド時間残してるだけでとくに署名的な事はしていないが、必要なら内容にCRCなりMD5なり生成して入れておけばいいんじゃない?みたいな(適当)
Exe版のコメント未修正と環境変数じゃなくてもよかったものを通常の変数にしてわかりやすくなるのなら修正。
7zipで圧縮する部分もイベントを変えてUIから差し込みできるよう検討。
できるだけ共通化(というか1本にできそう)と、環境変数の既定値(未設定なら既定値反映)処理の追加する。
両方に使える版をappveyor.ymlとして追加。
テストはまだ雑にしかやってない。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
あんまり調整してないドラフト版