

{"id":598,"date":"2026-12-01T17:00:03","date_gmt":"2026-12-01T09:00:03","guid":{"rendered":"https:\/\/6589jk.cn\/?p=598"},"modified":"2026-12-01T17:00:59","modified_gmt":"2026-12-01T09:00:59","slug":"%e5%90%8d%e4%be%a6%e6%8e%a2%e7%9a%84%e7%a0%b4%e6%a1%88%e7%ac%94%e8%ae%b0%ef%bc%9a%e8%ae%a9%e7%a8%8b%e5%ba%8f%e5%9c%a8%e7%bc%96%e8%af%91%e6%97%b6%e8%87%aa%e5%b7%b1%e8%ae%b0%e4%b8%8b-git-%e6%8f%90","status":"publish","type":"post","link":"https:\/\/6589jk.cn\/index.php\/2026\/12\/01\/%e5%90%8d%e4%be%a6%e6%8e%a2%e7%9a%84%e7%a0%b4%e6%a1%88%e7%ac%94%e8%ae%b0%ef%bc%9a%e8%ae%a9%e7%a8%8b%e5%ba%8f%e5%9c%a8%e7%bc%96%e8%af%91%e6%97%b6%e8%87%aa%e5%b7%b1%e8%ae%b0%e4%b8%8b-git-%e6%8f%90\/","title":{"rendered":"\u540d\u4fa6\u63a2\u7684\u7834\u6848\u7b14\u8bb0\uff1a\u8ba9\u7a0b\u5e8f\u5728\u7f16\u8bd1\u65f6\u81ea\u5df1\u8bb0\u4e0b git \u63d0\u4ea4\u53f7"},"content":{"rendered":"<p>\u6848\u5b50\u662f\u8fd9\u6837\u5f00\u573a\u7684\uff1a\u7528\u6237\u8bf4\u300c\u4e0a\u4e00\u7248\u662f\u597d\u7684\uff0c\u8fd9\u4e00\u7248\u574f\u4e86\u300d\uff0c\u800c\u4f60\u624b\u4e0a\u53ea\u6709\u4e00\u4e2a\u5b89\u88c5\u5305\u3001\u4e00\u4e2a\u5199\u7740 1.0.0 \u7684\u7248\u672c\u53f7\uff0c\u4ee5\u53ca\u4e00\u53e5\u300c\u5927\u6982\u662f\u4e0a\u5468\u6539\u7684\u90a3\u6b21\u300d\u3002<\/p>\n<p>\u7248\u672c\u53f7\u662f\u7ed9\u4eba\u770b\u7684\uff0c\u63d0\u4ea4\u53f7\u624d\u662f\u7ed9\u6848\u5b50\u7834\u7684\u3002\u524d\u8005\u53ef\u4ee5\u624b\u6539\u3001\u53ef\u4ee5\u88ab\u590d\u7528\u3001\u53ef\u4ee5\u5728\u4e09\u4e2a\u4e0d\u540c\u7684\u5305\u91cc\u957f\u5f97\u4e00\u6a21\u4e00\u6837\uff1b\u540e\u8005\u552f\u4e00\u6807\u8bc6\u4e00\u5768\u4ee3\u7801\u7684\u72b6\u6001\u3002\u6240\u4ee5\u540d\u4fa6\u63a2\u7684\u89c4\u77e9\u662f\uff1a\u8ba9\u7a0b\u5e8f\u5728\u7f16\u8bd1\u65f6\u5c31\u628a\u81ea\u5df1\u7684\u6307\u7eb9\u7f1d\u8fdb\u8eab\u4f53\u91cc\uff0c\u8fd0\u884c\u65f6\u81ea\u5df1\u62a5\u51fa\u6765\uff0c\u522b\u6307\u671b\u65c1\u8fb9\u90a3\u4e2a\u6587\u672c\u6587\u4ef6\u3002<\/p>\n<p>\u8fd9\u7bc7\u662f\u5b8c\u6574\u7684\u529e\u6848\u8bb0\u5f55\uff1a\u4ece\u300c\u53d1\u5e03\u65f6\u987a\u624b\u751f\u6210\u4e00\u4e2a\u8bb0\u5f55\u65f6\u95f4\u7684 txt\u300d\u8fd9\u79cd\u542c\u8d77\u6765\u5f88\u65b9\u4fbf\u3001\u5b9e\u9645\u4e0a\u4ec0\u4e48\u90fd\u8bc1\u660e\u4e0d\u4e86\u7684\u571f\u529e\u6cd5\uff0c\u6362\u6210\u7f16\u8bd1\u671f\u5199\u8fdb\u7a0b\u5e8f\u96c6\u5143\u6570\u636e\u3001\u8fd0\u884c\u65f6\u96f6\u4f9d\u8d56\u8bfb\u53d6\u7684\u505a\u6cd5\u3002<\/p>\n<h2>\u7b2c\u4e00\u73b0\u573a\uff1a\u90a3\u4e2a\u4f1a\u6492\u8c0e\u7684 txt<\/h2>\n<p>\u65e7\u7684\u53d1\u5e03\u6d41\u7a0b\u5f88\u6734\u7d20\u2014\u2014<code>dotnet publish<\/code> \u5b8c\u6210\u4e4b\u540e\uff0c\u5f80\u8f93\u51fa\u76ee\u5f55\u6254\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\uff0c\u5185\u5bb9\u662f\u90a3\u4e00\u523b\u7684\u65f6\u95f4\u6233\u3002\u5f53\u65f6\u89c9\u5f97\u633a\u806a\u660e\uff1a\u88c5\u4e0a\u4e4b\u540e\u770b\u4e00\u773c\u5c31\u77e5\u9053\u5305\u662f\u4ec0\u4e48\u65f6\u5019\u51fa\u7684\u3002<\/p>\n<p>\u540e\u6765\u53d1\u73b0\u5b83\u51e0\u4e4e\u6bcf\u6761\u90fd\u7ad9\u4e0d\u4f4f\uff1a<\/p>\n<ul>\n<li><strong>\u5b83\u548c\u4ee3\u7801\u65e0\u5173\uff0c\u53ea\u548c\u65f6\u95f4\u6709\u5173\u3002<\/strong>\u77e5\u9053\u300c10 \u6708 31 \u65e5 15:20 \u6253\u5305\u300d\u5b8c\u5168\u65e0\u6cd5\u56de\u7b54\u300c\u8fd9\u662f\u54ea\u4e00\u6b21\u63d0\u4ea4\u300d\u3002<\/li>\n<li><strong>\u5b83\u4f1a\u6b8b\u7559\u3002<\/strong>\u4e0a\u4e00\u6b21\u53d1\u5e03\u7684\u6587\u4ef6\u8fd8\u5728\u76ee\u5f55\u91cc\u8eba\u7740\uff0c\u65b0\u5305\u4e0d\u91cd\u65b0\u751f\u6210\u4e5f\u4e0d\u4f1a\u62a5\u9519\uff0c\u770b\u8d77\u6765\u53cd\u800c\u50cf\u662f\u65b0\u7684\u3002<\/li>\n<li><strong>\u5b83\u662f\u53e6\u4e00\u4e2a\u6587\u4ef6\u3002<\/strong>\u590d\u5236\u3001\u538b\u7f29\u3001\u505a\u5b89\u88c5\u5305\u3001\u53ea\u62ff exe \u53bb\u73b0\u573a\uff0c\u4efb\u4f55\u4e00\u6b65\u6f0f\u6389\u5b83\uff0c\u8bc1\u636e\u5c31\u6ca1\u4e86\u3002<\/li>\n<li><strong>\u5b83\u53ef\u88ab\u968f\u624b\u6539\u3002<\/strong>\u6ca1\u6709\u6821\u9a8c\uff0c\u6ca1\u6709\u7b7e\u540d\uff0c\u6539\u4e2a\u65f6\u95f4\u4e5f\u5c31\u662f\u8bb0\u4e8b\u672c\u4e24\u79d2\u949f\u7684\u4e8b\u3002<\/li>\n<\/ul>\n<p>\u4e00\u53e5\u8bdd\uff1a\u8fd9\u4e0d\u662f\u8bc1\u636e\uff0c\u662f\u5e72\u6270\u9879\u3002\u73b0\u573a\u5df2\u7ecf\u591f\u4e71\u4e86\uff0c\u4e0d\u9700\u8981\u518d\u591a\u4e00\u4e2a\u4f1a\u8bf4\u8c0e\u7684\u8bc1\u4eba\u3002<\/p>\n<h2>\u7834\u6848\u601d\u8def<\/h2>\n<p>\u5148\u7acb\u4e09\u6761\u786c\u8981\u6c42\uff0c\u514d\u5f97\u53c8\u505a\u51fa\u4e00\u4e2a\u300c\u770b\u7740\u80fd\u7528\u300d\u7684\u66ff\u4ee3\u54c1\uff1a<\/p>\n<ol>\n<li>\u7f16\u8bd1\u671f\u5c31\u786e\u5b9a\uff0c\u4e0d\u80fd\u4f9d\u8d56\u53d1\u5e03\u673a\u4e0a\u989d\u5916\u7684\u811a\u672c\u6216\u540e\u7eed\u5904\u7406\uff1b<\/li>\n<li>\u76ee\u6807\u673a\u5668\u4e0d\u9700\u8981\u88c5 git\uff0c\u4e5f\u4e0d\u9700\u8981\u8054\u7f51\uff1b<\/li>\n<li>\u7a0b\u5e8f\u81ea\u5df1\u80fd\u8bfb\u5230\uff0c\u4e0d\u4f9d\u8d56\u4efb\u4f55\u5916\u90e8\u6587\u4ef6\u3002<\/li>\n<\/ol>\n<p>\u7ffb\u8bd1\u6210 .NET \u7684\u8bed\u8a00\u5c31\u662f\uff1a<strong>\u7f16\u8bd1\u65f6\u628a git \u4fe1\u606f\u5199\u8fdb\u7a0b\u5e8f\u96c6\u5143\u6570\u636e\uff08<code>AssemblyMetadataAttribute<\/code>\uff09\uff0c\u8fd0\u884c\u65f6\u7528\u53cd\u5c04\u8bfb<\/strong>\u3002\u7b49\u540c\u4e8e\u628a\u6307\u7eb9\u76f4\u63a5\u7eb9\u5728\u7a0b\u5e8f\u8eab\u4e0a\uff0cdll \u8d70\u5230\u54ea\uff0c\u8bc1\u636e\u8ddf\u5230\u54ea\u3002<\/p>\n<h2>\u7b2c\u4e00\u6b65\uff1a\u8ba9 MSBuild \u5728\u7f16\u8bd1\u524d\u8dd1\u4e00\u904d git<\/h2>\n<p>\u9700\u8981\u7684\u7ebf\u7d22\u53ea\u6709\u4e09\u6761\uff1a\u5f53\u524d\u5206\u652f\u3001\u77ed\u63d0\u4ea4\u53f7\u3001\u5de5\u4f5c\u533a\u662f\u5426\u5e72\u51c0\u3002\u653e\u5728 csproj \u91cc\u5c31\u662f\u4e00\u4e2a <code>BeforeTargets=\"CoreCompile\"<\/code> \u7684\u76ee\u6807\uff1a<\/p>\n<pre><code>&lt;Target Name=\"GenerateGitRevision\" BeforeTargets=\"CoreCompile\"\n        Condition=\"'$(DesignTimeBuild)' != 'true'\"&gt;\n  &lt;PropertyGroup&gt;\n    &lt;GitRevisionFile&gt;$(MSBuildProjectDirectory)\\obj\\GitRevision.g.cs&lt;\/GitRevisionFile&gt;\n    &lt;GitExe Condition=\"'$(GitExe)' == ''\"&gt;git&lt;\/GitExe&gt;\n  &lt;\/PropertyGroup&gt;\n\n  &lt;Exec Command=\"&quot;$(GitExe)&quot; rev-parse --abbrev-ref HEAD\"\n        WorkingDirectory=\"$(MSBuildProjectDirectory)\"\n        ContinueOnError=\"true\" IgnoreExitCode=\"true\" EchoOff=\"true\"\n        ConsoleToMSBuild=\"true\" StandardOutputImportance=\"low\"&gt;\n    &lt;Output TaskParameter=\"ConsoleOutput\" ItemName=\"_GitBranchOut\" \/&gt;\n    &lt;Output TaskParameter=\"ExitCode\" PropertyName=\"_GitBranchExitCode\" \/&gt;\n  &lt;\/Exec&gt;\n\n  &lt;!-- \u540c\u7406\u518d\u6765\u4e24\u6761\uff1a\n       git rev-parse --short HEAD\n       git status --porcelain --ignore-submodules -- . --&gt;\n&lt;\/Target&gt;<\/code><\/pre>\n<p>\u51e0\u4e2a\u7ec6\u8282\u503c\u5f97\u5355\u72ec\u8bf4\u6e05\u695a\uff0c\u56e0\u4e3a\u5b83\u4eec\u662f\u8fd9\u5957\u4e1c\u897f\u80fd\u4e0d\u80fd\u6d3b\u4e0b\u6765\u7684\u5173\u952e\uff1a<\/p>\n<ul>\n<li><code>ContinueOnError<\/code> + <code>IgnoreExitCode<\/code>\uff1aCI \u4e0a\u53ef\u80fd\u662f\u6e90\u7801\u538b\u7f29\u5305\u3001\u53ef\u80fd\u662f\u6d45\u514b\u9686\u3001\u53ef\u80fd\u538b\u6839\u6ca1\u88c5 git\u3002\u6784\u5efa\u4e0d\u8be5\u56e0\u4e3a\u300c\u67e5\u4e0d\u5230\u6307\u7eb9\u300d\u76f4\u63a5\u5931\u8d25\uff0c\u4f46\u5728\u6ca1\u6709\u6307\u7eb9\u65f6\u8981\u8001\u8001\u5b9e\u5b9e\u9000\u56de <code>unknown<\/code>\u3002<\/li>\n<li><code>WorkingDirectory<\/code> \u6307\u5230\u9879\u76ee\u76ee\u5f55\uff1amonorepo \u91cc\u5b50\u9879\u76ee\u7684 git \u4e0a\u4e0b\u6587\u624d\u4e0d\u4f1a\u8dd1\u504f\u3002<\/li>\n<li>\u628a <code>ExitCode<\/code> \u4e5f\u63a5\u51fa\u6765\uff1a\u53ea\u6709\u9000\u51fa\u7801\u662f 0 \u624d\u8ba4\u4e3a\u8fd9\u6761\u7ebf\u7d22\u6709\u6548\u3002<code>Exec<\/code> \u5728\u5931\u8d25\u65f6\u8f93\u51fa\u7684\u7a7a\u5b57\u7b26\u4e32\u5f88\u5bb9\u6613\u88ab\u5f53\u6210\u300c\u5206\u652f\u540d\u662f\u7a7a\u300d\u3002<\/li>\n<\/ul>\n<p>\u4e09\u6761\u547d\u4ee4\u8dd1\u5b8c\uff0c\u7528\u5c5e\u6027\u628a\u7ed3\u679c\u6446\u597d\uff0c\u518d\u62fc\u5185\u5bb9\uff1a<\/p>\n<pre><code>&lt;PropertyGroup&gt;\n  &lt;GitBranch Condition=\"'$(_GitBranchExitCode)' == '0'\"&gt;@(_GitBranchOut)&lt;\/GitBranch&gt;\n  &lt;GitBranch Condition=\"'$(GitBranch)' == ''\"&gt;unknown&lt;\/GitBranch&gt;\n  &lt;GitBranch Condition=\"'$(GitBranch)' == 'HEAD'\"&gt;detached&lt;\/GitBranch&gt;\n  &lt;GitCommit Condition=\"'$(_GitCommitExitCode)' == '0'\"&gt;@(_GitCommitOut)&lt;\/GitCommit&gt;\n  &lt;GitCommit Condition=\"'$(GitCommit)' == ''\"&gt;unknown&lt;\/GitCommit&gt;\n  &lt;GitIsDirty Condition=\"'$(_GitStatusExitCode)' == '0' and '@(_GitDirtyOut)' != ''\"&gt;true&lt;\/GitIsDirty&gt;\n  &lt;GitIsDirty Condition=\"'$(_GitStatusExitCode)' != '0' or '@(_GitDirtyOut)' == ''\"&gt;false&lt;\/GitIsDirty&gt;\n&lt;\/PropertyGroup&gt;<\/code><\/pre>\n<p>\u6ce8\u610f <code>HEAD<\/code> \u90a3\u4e2a\u5206\u652f\u5224\u65ad\uff1aCI \u6309 tag \u68c0\u51fa\u65f6\u662f\u6e38\u79bb\u5934\uff0c<code>rev-parse --abbrev-ref HEAD<\/code> \u4f1a\u76f4\u63a5\u5410\u51fa <code>HEAD<\/code>\uff0c\u4e0d\u5904\u7406\u7684\u8bdd\u65e5\u5fd7\u91cc\u5c31\u4f1a\u51fa\u73b0\u300cHEAD@a1b2c3d\u300d\u8fd9\u79cd\u8c01\u770b\u90fd\u8981\u6123\u4e00\u4e0b\u7684\u4e1c\u897f\u3002<\/p>\n<p>AAO\uff01\u6307\u7eb9\u9f50\u4e86\uff0c\u53ef\u4ee5\u5f00\u59cb\u5199\u4e86\u3002<\/p>\n<h2>\u7b2c\u4e8c\u6b65\uff1a\u628a\u7ed3\u679c\u5199\u6210\u4e00\u884c C#<\/h2>\n<p>MSBuild \u6709\u4e2a\u5f88\u597d\u7528\u7684\u4efb\u52a1\u53eb <code>WriteLinesToFile<\/code>\uff0c\u76f4\u63a5\u751f\u6210\u4e00\u4e2a\u53ea\u542b\u7a0b\u5e8f\u96c6\u7279\u6027\u7684 C# \u6587\u4ef6\uff1a<\/p>\n<pre><code>&lt;ItemGroup&gt;\n  &lt;_GitSourceLine Include=\"\/\/ \u7531 GenerateGitRevision \u76ee\u6807\u751f\u6210\uff0c\u4e0d\u8981\u624b\u6539\u3002\" \/&gt;\n  &lt;_GitSourceLine Include=\"[assembly: System.Reflection.AssemblyMetadata(&quot;GitBranch&quot;, &quot;$(GitBranch)&quot;)]\" \/&gt;\n  &lt;_GitSourceLine Include=\"[assembly: System.Reflection.AssemblyMetadata(&quot;GitCommit&quot;, &quot;$(GitCommit)&quot;)]\" \/&gt;\n  &lt;_GitSourceLine Include=\"[assembly: System.Reflection.AssemblyMetadata(&quot;GitIsDirty&quot;, &quot;$(GitIsDirty)&quot;)]\" \/&gt;\n&lt;\/ItemGroup&gt;\n\n&lt;WriteLinesToFile File=\"$(GitRevisionFile)\" Lines=\"@(_GitSourceLine)\"\n                  Overwrite=\"true\" WriteOnlyWhenDifferent=\"true\" Encoding=\"UTF-8\" \/&gt;<\/code><\/pre>\n<p>\u751f\u6210\u51fa\u6765\u7684 <code>obj\\GitRevision.g.cs<\/code> \u5927\u6982\u957f\u8fd9\u6837\uff0c\u6734\u7d20\u5f97\u8ba9\u4eba\u653e\u5fc3\uff1a<\/p>\n<pre><code>\/\/ \u7531 GenerateGitRevision \u76ee\u6807\u751f\u6210\uff0c\u4e0d\u8981\u624b\u6539\u3002\n[assembly: System.Reflection.AssemblyMetadata(\"GitBranch\", \"main\")]\n[assembly: System.Reflection.AssemblyMetadata(\"GitCommit\", \"a1b2c3d\")]\n[assembly: System.Reflection.AssemblyMetadata(\"GitIsDirty\", \"true\")]<\/code><\/pre>\n<p>\u7136\u540e\u5fc5\u987b\u663e\u5f0f\u628a\u5b83\u52a0\u8fdb\u7f16\u8bd1\uff0c\u56e0\u4e3a SDK \u9ed8\u8ba4\u7684\u6e90\u7801 glob \u662f\u6392\u9664 <code>obj<\/code> \u76ee\u5f55\u7684\u2014\u2014\u4e0d\u5199\u8fd9\u884c\uff0c\u6587\u4ef6\u751f\u6210\u4e86\u4e5f\u4e0d\u4f1a\u88ab\u7f16\u8fdb\u53bb\uff0c\u767d\u5fd9\uff1a<\/p>\n<pre><code>&lt;ItemGroup Condition=\"'$(DesignTimeBuild)' != 'true'\"&gt;\n  &lt;Compile Include=\"$(MSBuildProjectDirectory)\\obj\\GitRevision.g.cs\" \/&gt;\n&lt;\/ItemGroup&gt;<\/code><\/pre>\n<p>\u4e24\u5904 <code>DesignTimeBuild<\/code> \u6761\u4ef6\u4e5f\u662f\u523b\u610f\u7684\uff1aIDE \u7684\u8bbe\u8ba1\u5668\u4f1a\u505a\u5927\u91cf\u300c\u5047\u7f16\u8bd1\u300d\uff0c\u90a3\u4e9b\u7f16\u8bd1\u4e0d\u9700\u8981\u6307\u7eb9\uff0c\u4e5f\u4e0d\u8be5\u6bcf\u6b21\u90fd\u53bb\u6572 git\u3001\u91cd\u5199\u6587\u4ef6\u3002\u8df3\u8fc7\u5b83\u4eec\uff0c\u8bbe\u8ba1\u5668\u624d\u4e0d\u4f1a\u88ab\u62d6\u6162\u3002<\/p>\n<h2>\u7b2c\u4e09\u6b65\uff1a\u8fd0\u884c\u65f6\u628a\u6307\u7eb9\u8bfb\u51fa\u6765<\/h2>\n<p>\u8bfb\u53d6\u4fa7\u4e0d\u9700\u8981\u4efb\u4f55\u5305\uff0c\u53cd\u5c04\u5c31\u591f\uff1a<\/p>\n<pre><code>public static class GitInfo\n{\n    public const string Unknown = \"unknown\";\n\n    private static readonly IReadOnlyDictionary&lt;string, string&gt; Metadata =\n        typeof(GitInfo).Assembly\n            .GetCustomAttributes&lt;AssemblyMetadataAttribute&gt;()\n            .Where(a =&gt; !string.IsNullOrEmpty(a.Key) &amp;&amp; a.Value is not null)\n            .GroupBy(a =&gt; a.Key!, StringComparer.OrdinalIgnoreCase)\n            .ToDictionary(g =&gt; g.Key, g =&gt; g.First().Value!,\n                          StringComparer.OrdinalIgnoreCase);\n\n    public static string Branch =&gt; Get(\"GitBranch\");\n    public static string Commit =&gt; Get(\"GitCommit\");\n\n    public static bool IsDirty =&gt;\n        string.Equals(Get(\"GitIsDirty\"), \"true\", StringComparison.OrdinalIgnoreCase);\n\n    public static string Revision =&gt;\n        IsKnown ? $\"{Branch}@{Commit}{(IsDirty ? \"*\" : string.Empty)}\" : Unknown;\n\n    public static string Version { get; } = ReadVersion();\n\n    public static string DisplayVersion =&gt; IsKnown ? $\"{Version} ({Revision})\" : Version;\n\n    private static bool IsKnown =&gt;\n        !string.Equals(Commit, Unknown, StringComparison.OrdinalIgnoreCase);\n\n    private static string Get(string key) =&gt;\n        Metadata.TryGetValue(key, out var value) &amp;&amp; !string.IsNullOrWhiteSpace(value)\n            ? value : Unknown;\n}<\/code><\/pre>\n<p>\u7248\u672c\u53f7\u4ece <code>AssemblyInformationalVersion<\/code> \u62ff\uff0c\u5e76\u4e14\u8981\u6309 <code>+<\/code> \u5207\u5f00\u518d\u53d6\u524d\u534a\u6bb5\u2014\u2014SDK \u5728\u68c0\u6d4b\u5230 git \u4ed3\u5e93\u65f6\u4f1a\u7ed9\u5b83\u8865\u4e00\u4e2a <code>+&lt;sha&gt;<\/code> \u540e\u7f00\uff0c\u4e0d\u5207\u7684\u8bdd\u7248\u672c\u53f7\u91cc\u4f1a\u6df7\u8fdb\u4e24\u5957\u63d0\u4ea4\u4fe1\u606f\uff0c\u770b\u8d77\u6765\u50cf\u7cbe\u795e\u5206\u88c2\u3002<\/p>\n<pre><code>private static string ReadVersion()\n{\n    var assembly = typeof(GitInfo).Assembly;\n    var informational = assembly\n        .GetCustomAttribute&lt;AssemblyInformationalVersionAttribute&gt;()?.InformationalVersion;\n    var version = informational?.Split('+')[0];\n    return string.IsNullOrWhiteSpace(version)\n        ? assembly.GetName().Version?.ToString(3) ?? Unknown\n        : version;\n}<\/code><\/pre>\n<p>\u6700\u540e\u627e\u4e2a\u663e\u773c\u7684\u5730\u65b9\u628a\u5b83\u6302\u51fa\u53bb\u3002\u684c\u9762\u7a0b\u5e8f\u6700\u7701\u4e8b\u7684\u5c31\u662f\u6807\u9898\u680f\u548c\u542f\u52a8\u65e5\u5fd7\uff1a<\/p>\n<pre><code>TitleInfo = $\"MyApp  {GitInfo.DisplayVersion}\";\nlogger.Info($\"\u6784\u5efa\u4fe1\u606f\uff1a{GitInfo.DisplayVersion}\");<\/code><\/pre>\n<p>\u6548\u679c\u662f <code>MyApp  1.0.0 (main@a1b2c3d)<\/code>\uff0c\u6709\u672a\u63d0\u4ea4\u6539\u52a8\u65f6\u53d8\u6210 <code>(main@a1b2c3d*)<\/code>\u3002\u73b0\u573a\u53ea\u8981\u622a\u4e2a\u56fe\u53d1\u8fc7\u6765\uff0c\u6848\u5b50\u5f53\u573a\u5c31\u7834\u4e00\u534a\u4e86\u3002<\/p>\n<h2>\u52a0\u5206\u7ebf\u7d22\uff1a\u51e0\u4e2a\u8e29\u8fc7\u7684\u5751<\/h2>\n<ol>\n<li><strong><code>WriteOnlyWhenDifferent=\"true\"<\/code> \u4e0d\u662f\u53ef\u9009\u9879\u3002<\/strong>\u4e0d\u52a0\u5b83\uff0c\u6bcf\u6b21\u7f16\u8bd1\u90fd\u4f1a\u91cd\u5199\u8fd9\u4e2a\u6587\u4ef6\uff0c\u65f6\u95f4\u6233\u4e00\u53d8\uff0c\u589e\u91cf\u7f16\u8bd1\u5c31\u88ab\u6253\u7834\uff0c\u6574\u4e2a\u9879\u76ee\u5168\u91cf\u91cd\u7f16\u3002\u4e3a\u4e86\u8bb0\u4f4f\u4e00\u4e2a\u63d0\u4ea4\u53f7\uff0c\u628a\u7f16\u8bd1\u901f\u5ea6\u642d\u8fdb\u53bb\uff0c\u4e0d\u5212\u7b97\u3002<\/li>\n<li><strong>\u522b\u628a commit \u585e\u8fdb <code>AssemblyFileVersion<\/code>\u3002<\/strong>\u90a3\u662f\u7ed9\u6587\u4ef6\u7cfb\u7edf\u548c\u5b89\u88c5\u5305\u505a\u6bd4\u8f83\u7528\u7684\uff0c\u683c\u5f0f\u3001\u5bf9\u9f50\u3001\u5347\u7ea7\u5224\u65ad\u90fd\u4f9d\u8d56\u5b83\u3002\u60f3\u79c0\u6307\u7eb9\u5c31\u65b0\u5f00\u4e00\u4e2a\u4f4d\u7f6e\uff0c\u4e0d\u8981\u6c61\u67d3\u7248\u672c\u8bed\u4e49\u3002<\/li>\n<li><strong>\u300c\u4e0d\u77e5\u9053\u300d\u5fc5\u987b\u663e\u5f0f\u5931\u8d25\u3002<\/strong>\u65e0 git \u65f6\u9000\u56de <code>unknown<\/code> \u662f\u5bf9\u7684\uff0c\u4f46\u53d1\u5e03\u6d41\u6c34\u7ebf\u5e94\u8be5\u53cd\u8fc7\u6765\u68c0\u67e5\uff1a\u5982\u679c\u6253\u51fa\u6765\u7684\u6b63\u5f0f\u5305\u662f <code>unknown<\/code>\uff0c\u76f4\u63a5\u5224\u5931\u8d25\u3002\u628a\u300c\u4e0d\u77e5\u9053\u300d\u5f53\u6210\u300c\u53ef\u4ee5\u53d1\u5e03\u300d\uff0c\u7b49\u4e8e\u628a\u4e8b\u6545\u7559\u5230\u660e\u5e74\u3002<\/li>\n<li><strong>\u672c\u5730\u6784\u5efa\u6c38\u8fdc\u662f\u810f\u7684\u3002<\/strong><code>GitIsDirty<\/code> \u5728\u5f00\u53d1\u673a\u4e0a\u51e0\u4e4e\u5fc5\u7136\u4e3a <code>true<\/code>\uff0c\u5e26\u661f\u53f7\u4e0d\u4ee3\u8868\u5305\u6709\u95ee\u9898\uff1b\u4f46\u6b63\u5f0f\u53d1\u5e03\u524d\u786e\u8ba4\u4e00\u6b21\u5e72\u51c0\u72b6\u6001\uff0c\u4ef7\u503c\u5f88\u5927\u3002<\/li>\n<li><strong>\u591a\u4e2a\u9879\u76ee\u522b\u6284\u4e09\u4efd\u3002<\/strong>\u540c\u4e00\u4e2a\u4ed3\u5e93\u91cc\u51e0\u4e2a csproj \u5404\u81ea\u8d34\u4e00\u904d\u8fd9\u4e2a\u76ee\u6807\uff0c\u5f88\u5feb\u5c31\u51fa\u73b0\u300c\u6539\u4e86 A \u5fd8\u4e86 B\u300d\u3002\u62bd\u5230 <code>Directory.Build.targets<\/code> \u91cc\u7edf\u4e00\u6ce8\u5165\uff0c\u6216\u8005\u5728 props \u91cc\u7ed9\u6bcf\u4e2a\u9879\u76ee\u4e00\u4efd\uff0c\u662f\u66f4\u7701\u5fc3\u7684\u505a\u6cd5\u3002<\/li>\n<li><strong>\u5143\u6570\u636e\u91cc\u4e0d\u8981\u653e\u654f\u611f\u4fe1\u606f\u3002<\/strong>commit \u53ea\u662f\u4e00\u4e32\u54c8\u5e0c\uff0c\u5b89\u5168\uff1b\u4f46<strong>\u5206\u652f\u540d\u662f\u4eba\u5199\u7684<\/strong>\uff0c\u5f88\u5bb9\u6613\u5e26\u51fa\u5de5\u5355\u53f7\u3001\u5ba2\u6237\u540d\u3001\u751a\u81f3\u4e00\u53e5\u5185\u90e8\u5410\u69fd\u3002\u516c\u5f00\u53d1\u5e03\u7684\u5305\uff0c\u5148\u770b\u4e00\u773c\u81ea\u5df1\u5206\u652f\u53eb\u4ec0\u4e48\u3002<\/li>\n<li><strong><code>obj<\/code> \u4e0b\u7684\u751f\u6210\u6587\u4ef6\u4e0d\u8981\u63d0\u4ea4\u3002<\/strong>\u5b83\u6bcf\u6b21\u7f16\u8bd1\u90fd\u4f1a\u91cd\u7b97\uff0c\u63d0\u4ea4\u8fdb\u53bb\u53ea\u4f1a\u5236\u9020\u51b2\u7a81\u548c\u65e0\u610f\u4e49\u7684 diff\u3002<\/li>\n<\/ol>\n<h2>\u9a8c\u8bc1\uff1a\u5b83\u5230\u5e95\u8bf4\u4e86\u4ec0\u4e48<\/h2>\n<p>\u4e09\u6b65\u786e\u8ba4\uff0c\u4e0d\u7528\u731c\uff1a<\/p>\n<ol>\n<li>\u7f16\u8bd1\u540e\u5728\u542f\u52a8\u65e5\u5fd7\u91cc\u770b\u5230 <code>\u6784\u5efa\u4fe1\u606f\uff1a1.0.0 (main@a1b2c3d)<\/code>\uff1b<\/li>\n<li>\u7528\u4efb\u610f\u53cd\u7f16\u8bd1\u5de5\u5177\u6253\u5f00 dll\uff0c<code>AssemblyMetadata<\/code> \u91cc\u4e09\u6761\u7279\u6027\u90fd\u5728\uff1b<\/li>\n<li>\u628a publish \u51fa\u6765\u7684\u76ee\u5f55\u6574\u4e2a\u53d1\u7ed9\u522b\u4eba\uff0c\u4e0d\u9644\u5e26\u4efb\u4f55 txt\uff0c\u95ee\u4e00\u53e5\u300c\u4f60\u90a3\u8fb9\u6807\u9898\u680f\u5199\u7684\u662f\u4ec0\u4e48\u300d\u3002<\/li>\n<\/ol>\n<p>\u7b2c\u4e09\u6761\u5982\u679c\u8fc7\u5173\uff0c\u8fd9\u5957\u4e1c\u897f\u5c31\u7b97\u7ed3\u6848\u4e86\u2014\u2014\u5b83\u4e0d\u4f9d\u8d56\u8fd0\u6c14\uff0c\u4e5f\u4e0d\u4f9d\u8d56\u8c01\u8bb0\u5f97\u3002<\/p>\n<h2>\u7ed3\u6848\u9648\u8bcd<\/h2>\n<p>\u7248\u672c\u53f7\u56de\u7b54\u7684\u662f\u300c\u4f60\u7ed9\u6211\u7684\u662f\u7b2c\u51e0\u7248\u300d\uff0c\u63d0\u4ea4\u53f7\u56de\u7b54\u7684\u662f\u300c\u4f60\u7ed9\u6211\u7684\u662f\u54ea\u4e00\u884c\u4ee3\u7801\u300d\u3002\u524d\u8005\u9002\u5408\u5199\u5728\u4e0b\u8f7d\u9875\u4e0a\uff0c\u540e\u8005\u9002\u5408\u5728\u51cc\u6668\u4e24\u70b9\u6392\u67e5\u73b0\u573a\u95ee\u9898\u65f6\u6551\u547d\u3002<\/p>\n<p>\u628a\u8bc1\u636e\u7f1d\u8fdb\u7a0b\u5e8f\u672c\u8eab\uff0c\u987a\u624b\u628a\u90a3\u4e2a\u4f1a\u6492\u8c0e\u7684\u65f6\u95f4\u6233 txt \u5220\u6389\uff0c\u6574\u4e2a\u6d41\u7a0b\u5c31\u5c11\u4e86\u4e00\u4e2a\u4e5f\u8bb8\u6c38\u8fdc\u4e0d\u4f1a\u6709\u4eba\u770b\u3001\u4f46\u4e00\u65e6\u88ab\u770b\u5c31\u4f1a\u88ab\u8bef\u5bfc\u7684\u6587\u4ef6\u3002\u540d\u4fa6\u63a2\u7684\u504f\u89c1\u5927\u6982\u5c31\u662f\u8fd9\u6837\uff1a\u5b81\u53ef\u6ca1\u6709\u8bc1\u4eba\uff0c\u4e5f\u4e0d\u8981\u4e00\u4e2a\u4e0d\u53ef\u9760\u7684\u8bc1\u4eba\u3002<\/p>\n<p>AAO\uff0c\u6536\u5de5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7248\u672c\u53f7\u53ea\u80fd\u8bf4\u6e05\u300c\u7b2c\u51e0\u7248\u300d\uff0c\u8bf4\u4e0d\u6e05\u300c\u54ea\u4e00\u884c\u4ee3\u7801\u300d\u3002\u8fd9\u7bc7\u8bb0\u5f55\u628a git \u5206\u652f\u4e0e\u63d0\u4ea4\u53f7\u5728\u7f16\u8bd1\u671f\u5199\u8fdb\u7a0b\u5e8f\u96c6\u5143\u6570\u636e\u3001\u8fd0\u884c\u65f6\u96f6\u4f9d\u8d56\u8bfb\u53d6\u7684\u5b8c\u6574\u505a\u6cd5\uff0c\u987a\u624b\u62c6\u6389\u90a3\u4e2a\u4f1a\u6492\u8c0e\u7684\u53d1\u5e03\u65f6\u95f4 txt\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_themeisle_gutenberg_block_has_review":false,"footnotes":""},"categories":[29],"tags":[57,5,39,151,152],"class_list":["post-598","post","type-post","status-publish","format-standard","hentry","category-29","tag-net","tag-c","tag-git","tag-msbuild","tag-152"],"_links":{"self":[{"href":"https:\/\/6589jk.cn\/index.php\/wp-json\/wp\/v2\/posts\/598","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/6589jk.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/6589jk.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/6589jk.cn\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/6589jk.cn\/index.php\/wp-json\/wp\/v2\/comments?post=598"}],"version-history":[{"count":1,"href":"https:\/\/6589jk.cn\/index.php\/wp-json\/wp\/v2\/posts\/598\/revisions"}],"predecessor-version":[{"id":599,"href":"https:\/\/6589jk.cn\/index.php\/wp-json\/wp\/v2\/posts\/598\/revisions\/599"}],"wp:attachment":[{"href":"https:\/\/6589jk.cn\/index.php\/wp-json\/wp\/v2\/media?parent=598"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/6589jk.cn\/index.php\/wp-json\/wp\/v2\/categories?post=598"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/6589jk.cn\/index.php\/wp-json\/wp\/v2\/tags?post=598"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}