Skip to content

Instantly share code, notes, and snippets.

@huanlin
huanlin / Movie.cs
Created April 14, 2020 17:52
Example of KeyedCollection
public class Movie
{
public string Id { get; set; }
public string Title { get; set; }
public int Stars { get; set; }
}
public class BuildScript : DefaultBuildScript
{
[SolutionFileName]
public string SolutionFileName => "source/MyApp.sln";
[BuildConfiguration]
public string BuildConfiguration { get; set; } = "Release"; // Debug or Release
protected override void ConfigureBuildProperties(IBuildPropertiesContext context)
{
public interface ILogger
{
// 這是原本我們熟悉的、沒有實作的介面方法。
void Log(string msg)
// 此方法提供了預設實作。C# 8 以後才能這樣寫。
void Error(Exception ex);
{
// 保存或輸出錯誤訊息。
}
using System;
using FlubuCore.Context;
using FlubuCore.Context.Attributes.BuildProperties;
using FlubuCore.IO;
using FlubuCore.Scripting;
using FlubuCore.Tasks.Attributes;
using FlubuCore.Tasks.Versioning;
namespace build
{
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
@huanlin
huanlin / _build.csproj
Last active March 26, 2020 19:08
Fix error in Nuke 0.24.7
<ItemGroup>
<PackageReference Include="Nuke.Common" Version="0.24.7" />
<PackageDownload Include="GitVersion.Tool" Version="[5.1.1]" />
</ItemGroup>
// 舊版 Program.cs 的 Main 函式:
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
// 新版 Program.cs 的 Main 函式:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
<RootNamespace>EasyBrailleEdit</RootNamespace>
<AssemblyName>EasyBrailleEdit</AssemblyName>
</PropertyGroup>
#nullable enable // 啟用 nullable 語法和警告
string? str1 = null;
#nullable disable // 關閉 nullable 語法和警告
string str2 = null;
<Project>
<PropertyGroup>
<Nullable>enable</Nullable>
<RunAnalyzersDuringBuild>true</RunAnalyzersDuringBuild>
<RunAnalyzersDuringLiveAnalysis>true</RunAnalyzersDuringLiveAnalysis>
</PropertyGroup>
</Project>