-
-
Save mzorec/2a1e7a0a0e48eccadc3a13f450d14deb 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.0.1 或更新的版本。 | |
namespace _Build | |
{ | |
public class BuildScript : DefaultBuildScript | |
{ | |
// 指定建置結果的輸出目錄。 | |
public FullPath OutputDir => RootDirectory.CombineWith("output"); | |
// 指定 .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 ConfigureBuildProperties(IBuildPropertiesContext context) | |
{ | |
context.Properties.Set(BuildProps.ProductId, "MyApp"); | |
context.Properties.Set(BuildProps.ProductName, "MyApp"); | |
} | |
protected override void ConfigureTargets(ITaskContext session) | |
{ | |
Console.WriteLine($"輸出目錄為 {OutputDir}"); | |
Console.WriteLine($"產品版本為 {Version}"); | |
Console.WriteLine("開始建置專案..."); | |
var target = session.CreateTarget("compile") | |
.SetDescription("編譯整個 solution。") | |
.AddCoreTask(x => x.Restore()) | |
.AddCoreTask(x => x.Build() | |
.Output(OutputDir) | |
.Version(ProductVersion.Version.ToString())); | |
} | |
} | |
} |
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 OutputDir => 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)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment