Last active
February 5, 2022 04:17
-
-
Save huanlin/e8121225b19f6fd3183703b1acaab192 to your computer and use it in GitHub Desktop.
This file contains 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
using System; | |
using FlubuCore.Context; | |
using FlubuCore.Context.Attributes.BuildProperties; | |
using FlubuCore.IO; | |
using FlubuCore.Scripting; | |
using FlubuCore.Tasks.Attributes; | |
using FlubuCore.Tasks.Versioning; | |
// 注意:需要 FlubuCore v5.1.8 或更新的版本。 | |
namespace _Build | |
{ | |
public class BuildScript : DefaultBuildScript | |
{ | |
// 指定建置結果的輸出目錄。 | |
public FullPath OutputDirectory => RootDirectory.CombineWith("output"); | |
[ProductId] | |
public string ProductId { get; set; } = "MyApp"; | |
// 指定 .sln 檔案。這裡加上了 "source/",是因為我把建置專案放在 repository 的跟目錄。 | |
[SolutionFileName] | |
public string SolutionFileName => RootDirectory.CombineWith("source/BuildAll.sln"); | |
[BuildConfiguration] | |
public string BuildConfiguration { get; set; } = "Release"; // Debug or Release | |
// 使用外部檔案來控制產品版本,檔案應放在 source 目錄下(跟 .sln 檔案同一層)。 | |
[FetchBuildVersionFromFile(ProjectVersionFileName = "ProductVersion.txt")] | |
public BuildVersion Version { get; set; } | |
protected override void ConfigureTargets(ITaskContext session) | |
{ | |
Console.WriteLine($"輸出目錄為 {OutputDirectory}"); | |
Console.WriteLine($"產品版本為 {Version}"); | |
var clean = session.CreateTarget("clean") | |
.SetDescription("Cleaning solution output folder.") | |
.AddCoreTask(x => x.Clean() | |
.CleanOutputDir()); | |
var compile = session.CreateTarget("compile") | |
.SetDescription("編譯整個 solution。") | |
.AddCoreTask(x => x.Build() | |
.Version(ProductVersion.Version.ToString())); | |
var publish = session.CreateTarget("publish") | |
.SetDescription("Publish binaries.") | |
.DependsOn(compile) | |
.AddCoreTask(x => x.Publish() | |
.OutputDirectory(OutputDirectory)); | |
} | |
} | |
} |
This file contains 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
public class BuildScript : DefaultBuildScript | |
{ | |
public FullPath OutputDirectory => RootDirectory.CombineWith("output"); | |
[BuildConfiguration] | |
public string BuildConfiguration { get; set; } = "Release"; // Debug or Release | |
// 使用外部檔案來控制產品版本,檔案應放在 source 目錄下(跟 .sln 檔案同一層目錄) | |
[FetchBuildVersionFromFile(ProjectVersionFileName = "ProductVersion.txt")] | |
public BuildVersion ProductVersion { get; set; } | |
public string VersionString => ProductVersion.Version.ToString(); | |
...... | |
protected override void ConfigureTargets(ITaskContext session) | |
{ | |
var target = session.CreateTarget("compile") | |
.SetDescription("Compile the solution.") | |
.AddCoreTask(x => | |
x.Build() | |
.Output(OutputDir) | |
.Version(VersionString) | |
.FileVersion(VersionString) | |
.AssemblyVersion(VersionString)); | |
} | |
} |
This file contains 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
using System; | |
using FlubuCore.Context; | |
using FlubuCore.Context.Attributes.BuildProperties; | |
using FlubuCore.IO; | |
using FlubuCore.Scripting; | |
/* | |
* 此範例展示 FlubuCore 搭配 MinVer 來指定應用程式的版本編號。已使用 FlubuCore v6.3.2 測試過。 | |
* 做法很簡單,只要把 MinVer 套件加入應用程式專案就行了,然後用 git tag 命令來指定應用程式的版本。 | |
* 除此之外,不用加入其他任何設定,建置腳本裡面也不用寫任何與版本編號有關的程式碼。 | |
*/ | |
namespace _Build | |
{ | |
public class BuildScript : DefaultBuildScript | |
{ | |
// 指定建置結果的輸出目錄。 | |
public FullPath OutputDirectory => RootDirectory.CombineWith("output"); | |
[ProductId] | |
public string ProductId { get; set; } = "MyApp"; | |
// 指定 .sln 檔案。這裡加上了 "source/",是因為我把建置專案放在 repository 的跟目錄。 | |
[SolutionFileName] | |
public string SolutionFileName => RootDirectory.CombineWith("Source/MyApp.sln"); | |
[BuildConfiguration] | |
public string BuildConfiguration { get; set; } = "Release"; // Debug or Release | |
protected override void ConfigureTargets(ITaskContext session) | |
{ | |
var clean = session.CreateTarget("clean") | |
.SetDescription("Cleaning solution output folder.") | |
.AddCoreTask(x => x.Clean() | |
.CleanOutputDir()); | |
var compile = session.CreateTarget("compile") | |
.SetDescription("編譯 solution。") | |
.AddCoreTask(x => x.Build()); | |
var publish = session.CreateTarget("publish") | |
.SetDescription("Publish binaries.") | |
.DependsOn(compile) | |
.AddCoreTask(x => x.Publish() | |
.OutputDirectory(OutputDirectory)); | |
} | |
} | |
} |
Look at the changes in https://gist.github.com/mzorec/560fde55b162262cbb153b156d71a03e
Cool. I've taken your changes and update my gist. Thank you for your help!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Look at the changes in https://gist.github.com/mzorec/560fde55b162262cbb153b156d71a03e