{"id":625,"date":"2025-12-07T15:41:18","date_gmt":"2025-12-07T07:41:18","guid":{"rendered":"https:\/\/www.52runoob.com\/?p=625"},"modified":"2025-12-07T15:41:18","modified_gmt":"2025-12-07T07:41:18","slug":"net_core%e9%a1%b9%e7%9b%ae%e9%83%a8%e7%bd%b2%e6%97%b6%e8%87%aa%e5%8a%a8%e6%a3%80%e6%9f%a5%e5%b9%b6%e4%bf%ae%e5%a4%8d%e7%bc%ba%e5%b0%91%e7%9a%84%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f%e5%80%bc%e8%84%9a","status":"publish","type":"post","link":"https:\/\/www.52runoob.com\/index.php\/2025\/12\/07\/net_core%e9%a1%b9%e7%9b%ae%e9%83%a8%e7%bd%b2%e6%97%b6%e8%87%aa%e5%8a%a8%e6%a3%80%e6%9f%a5%e5%b9%b6%e4%bf%ae%e5%a4%8d%e7%bc%ba%e5%b0%91%e7%9a%84%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f%e5%80%bc%e8%84%9a\/","title":{"rendered":".net_core\u9879\u76ee\u90e8\u7f72\u65f6\u81ea\u52a8\u68c0\u67e5\u5e76\u4fee\u590d\u7f3a\u5c11\u7684\u73af\u5883\u53d8\u91cf\u503c\u811a\u672c\u7f16\u5199\u65b9\u6cd5(\u6700\u65b0)"},"content":{"rendered":"\n<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd <strong>\u300a.NET Core \u9879\u76ee\u90e8\u7f72\u65f6\u81ea\u52a8\u68c0\u67e5\u5e76\u4fee\u590d\u7f3a\u5c11\u7684\u73af\u5883\u53d8\u91cf\u503c\u811a\u672c\u7f16\u5199\u65b9\u6cd5\uff08\u6700\u65b0\u901a\u7528\u65b9\u6848\uff09\u300b<\/strong>\u3002<br>\u5305\u62ec <strong>Linux + Windows<\/strong> \u4e24\u5957\u811a\u672c\uff0c\u652f\u6301\uff1a<br>\u2714 \u81ea\u52a8\u68c0\u6d4b\u7f3a\u5931\u73af\u5883\u53d8\u91cf<br>\u2714 \u81ea\u52a8\u5199\u5165\u9ed8\u8ba4\u503c<br>\u2714 \u53ef\u7528\u4e8e CI\/CD\u3001Docker\u3001Nginx\/Kestrel \u90e8\u7f72<br>\u2714 \u9488\u5bf9 .NET Core \/ .NET 5\u20138 \u5168\u7248\u672c\u901a\u7528<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udfe6 \u4e00\u3001\u9700\u8981\u89e3\u51b3\u7684\u95ee\u9898<\/h1>\n\n\n\n<p>\u90e8\u7f72 .NET Core \u9879\u76ee\u65f6\uff0c\u7ecf\u5e38\u4f1a\u9047\u5230\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u73af\u5883\u53d8\u91cf\u5fd8\u8bb0\u8bbe\u7f6e<\/li>\n\n\n\n<li>\u73af\u5883\u53d8\u91cf\u4e3a\u7a7a\u5b57\u7b26\u4e32<\/li>\n\n\n\n<li>\u683c\u5f0f\u9519\u8bef\u5bfc\u81f4\u7a0b\u5e8f\u542f\u52a8\u5931\u8d25<\/li>\n\n\n\n<li>Docker \u5185\u73af\u5883\u53d8\u91cf\u672a\u4f20\u9012<\/li>\n\n\n\n<li>Linux systemd \u542f\u52a8\u65f6\u7f3a\u5931\u53d8\u91cf\u5bfc\u81f4\u5d29\u6e83<\/li>\n<\/ul>\n\n\n\n<p>\u4e3a\u907f\u514d\u624b\u52a8\u6392\u67e5\uff0c\u6211\u4eec\u53ef\u4ee5\u5199\u4e00\u5957\u811a\u672c\uff1a<\/p>\n\n\n\n<p><strong>\u81ea\u52a8\u68c0\u67e5 \u2192 \u81ea\u52a8\u4fee\u590d \u2192 \u81ea\u52a8\u8f93\u51fa\u6700\u7ec8\u914d\u7f6e<\/strong><\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udfe9 \u4e8c\u3001\u63a8\u8350\u7684\u68c0\u67e5\u903b\u8f91\uff08\u901a\u7528\uff09<\/h1>\n\n\n\n<p>\u4ee5\u4ee5\u4e0b 4 \u4e2a\u73af\u5883\u53d8\u91cf\u4e3a\u4f8b\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nDB_HOST\nDB_USER\nDB_PASSWORD\nJWT_KEY\n\n<\/pre><\/div>\n\n\n<p>\u811a\u672c\u9700\u8981\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u68c0\u67e5\u6bcf\u4e2a\u53d8\u91cf\u662f\u5426\u5b58\u5728<\/li>\n\n\n\n<li>\u82e5\u4e0d\u5b58\u5728 \u2192 \u81ea\u52a8\u5199\u5165\u9ed8\u8ba4\u503c<\/li>\n\n\n\n<li>\u82e5\u5b58\u5728\u4f46\u4e3a\u7a7a \u2192 \u81ea\u52a8\u4fee\u590d<\/li>\n\n\n\n<li>\u8f93\u51fa\u6700\u7ec8\u7ed3\u679c<\/li>\n\n\n\n<li>\u542f\u52a8 .NET Core \u7a0b\u5e8f<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udfe7 \u4e09\u3001Linux \u90e8\u7f72\u811a\u672c\uff08bash \u7248\uff0c\u9002\u5408 Docker \/ Kestrel \/ systemd\uff09<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udccc create file: <strong>check-env.sh<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#!\/bin\/bash\n\n# \u9700\u8981\u7684\u73af\u5883\u53d8\u91cf\u53ca\u9ed8\u8ba4\u503c\ndeclare -A DEFAULTS=(\n  &#x5B;&quot;DB_HOST&quot;]=&quot;localhost&quot;\n  &#x5B;&quot;DB_USER&quot;]=&quot;root&quot;\n  &#x5B;&quot;DB_PASSWORD&quot;]=&quot;123456&quot;\n  &#x5B;&quot;JWT_KEY&quot;]=&quot;default-key-123&quot;\n)\n\necho &quot;\ud83d\udd0d \u6b63\u5728\u68c0\u67e5\u73af\u5883\u53d8\u91cf...&quot;\n\nfor KEY in &quot;${!DEFAULTS&#x5B;@]}&quot;; do\n    VALUE=${!KEY}\n\n    if &#x5B; -z &quot;$VALUE&quot; ]; then\n        echo &quot;\u26a0\ufe0f \u73af\u5883\u53d8\u91cf $KEY \u7f3a\u5931\u6216\u4e3a\u7a7a\uff0c\u6b63\u5728\u81ea\u52a8\u4fee\u590d...&quot;\n        export &quot;$KEY=${DEFAULTS&#x5B;$KEY]}&quot;\n    else\n        echo &quot;\u2714 $KEY \u68c0\u6d4b\u6b63\u5e38&quot;\n    fi\ndone\n\necho &quot;&quot;\necho &quot;\ud83d\udccc \u6700\u7ec8\u4f7f\u7528\u7684\u73af\u5883\u53d8\u91cf\uff1a&quot;\nfor KEY in &quot;${!DEFAULTS&#x5B;@]}&quot;; do\n    echo &quot;$KEY=${!KEY}&quot;\ndone\n\necho &quot;&quot;\necho &quot;\ud83d\ude80 \u6b63\u5728\u542f\u52a8 .NET Core \u5e94\u7528...&quot;\ndotnet MyApp.dll\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u4f7f\u7528\u65b9\u5f0f<\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nchmod +x check-env.sh\n.\/check-env.sh\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2b50 \u81ea\u52a8\u6267\u884c\uff08systemd \u793a\u4f8b\uff09<\/h3>\n\n\n\n<p><code>\/etc\/systemd\/system\/myapp.service<\/code>\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nExecStart=\/bin\/bash \/var\/www\/myapp\/check-env.sh\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udfe6 \u56db\u3001Windows \u90e8\u7f72\u811a\u672c\uff08PowerShell \u6700\u65b0\u7248\uff09<\/h1>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udccc create file: <strong>check-env.ps1<\/strong><\/h3>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n$defaults = @{\n    &quot;DB_HOST&quot;      = &quot;localhost&quot;\n    &quot;DB_USER&quot;      = &quot;root&quot;\n    &quot;DB_PASSWORD&quot;  = &quot;123456&quot;\n    &quot;JWT_KEY&quot;      = &quot;default-key-123&quot;\n}\n\nWrite-Host &quot;\ud83d\udd0d \u6b63\u5728\u68c0\u67e5\u73af\u5883\u53d8\u91cf...&quot;\n\nforeach ($key in $defaults.Keys) {\n    $value = &#x5B;Environment]::GetEnvironmentVariable($key, &quot;Machine&quot;)\n\n    if (&#x5B;string]::IsNullOrEmpty($value)) {\n        Write-Host &quot;\u26a0\ufe0f \u53d8\u91cf $key \u7f3a\u5931\u6216\u4e3a\u7a7a\uff0c\u6b63\u5728\u5199\u5165\u9ed8\u8ba4\u503c...&quot;\n        &#x5B;Environment]::SetEnvironmentVariable($key, $defaults&#x5B;$key], &quot;Machine&quot;)\n    }\n    else {\n        Write-Host &quot;\u2714 $key \u68c0\u6d4b\u6b63\u5e38&quot;\n    }\n}\n\nWrite-Host &quot;&quot;\nWrite-Host &quot;\ud83d\udccc \u6700\u7ec8\u73af\u5883\u53d8\u91cf\uff1a&quot;\nforeach ($key in $defaults.Keys) {\n    Write-Host &quot;$key=&quot; (&#x5B;Environment]::GetEnvironmentVariable($key, &quot;Machine&quot;))\n}\n\nWrite-Host &quot;&quot;\nWrite-Host &quot;\ud83d\ude80 \u542f\u52a8 .NET Core \u5e94\u7528...&quot;\ndotnet &quot;C:\\deploy\\MyApp\\MyApp.dll&quot;\n\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\">\u2714 \u4f7f\u7528\u65b9\u5f0f<\/h3>\n\n\n\n<p>\u4ee5\u7ba1\u7406\u5458\u6743\u9650\u6267\u884c\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\npowershell.exe -ExecutionPolicy Bypass -File check-env.ps1\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udfe8 \u4e94\u3001\u5728 .NET Core \u8fd0\u884c\u65f6\u518d\u6b21\u68c0\u67e5\uff08\u53cc\u4fdd\u9669\uff09<\/h1>\n\n\n\n<p>Program.cs \u4e2d\u52a0\u5165\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nstring RequireEnv(string key)\n{\n    var val = Environment.GetEnvironmentVariable(key);\n\n    if (string.IsNullOrWhiteSpace(val))\n        throw new Exception($&quot;\u7f3a\u5c11\u5173\u952e\u73af\u5883\u53d8\u91cf: {key}&quot;);\n\n    return val;\n}\n\nbuilder.Configuration&#x5B;&quot;DB_HOST&quot;] = RequireEnv(&quot;DB_HOST&quot;);\nbuilder.Configuration&#x5B;&quot;DB_USER&quot;] = RequireEnv(&quot;DB_USER&quot;);\nbuilder.Configuration&#x5B;&quot;DB_PASSWORD&quot;] = RequireEnv(&quot;DB_PASSWORD&quot;);\nbuilder.Configuration&#x5B;&quot;JWT_KEY&quot;] = RequireEnv(&quot;JWT_KEY&quot;);\n\n<\/pre><\/div>\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udfea \u516d\u3001Docker + Kestrel \u90e8\u7f72\u65f6\u7684\u81ea\u52a8\u68c0\u67e5<\/h1>\n\n\n\n<p>Dockerfile\uff1a<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nCOPY check-env.sh \/app\/check-env.sh\nENTRYPOINT &#x5B;&quot;bash&quot;, &quot;\/app\/check-env.sh&quot;]\n\n<\/pre><\/div>\n\n\n<p>\u8fd9\u6837\u5bb9\u5668\u542f\u52a8\u65f6\u81ea\u52a8\u68c0\u67e5\u5e76\u6dfb\u52a0\u9ed8\u8ba4\u503c\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83d\udfeb \u4e03\u3001\u6700\u4f73\u5b9e\u8df5\u603b\u7ed3<\/h1>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u65b9\u6848<\/th><th>\u573a\u666f<\/th><\/tr><\/thead><tbody><tr><td>bash \u811a\u672c<\/td><td>Linux \/ Docker \/ Kestrel \/ Nginx<\/td><\/tr><tr><td>PowerShell \u811a\u672c<\/td><td>Windows IIS \/ Windows Server<\/td><\/tr><tr><td>Program.cs \u53cc\u4fdd\u9669<\/td><td>\u9632\u6b62\u9519\u6f0f\u5f15\u53d1\u8fd0\u884c\u65f6\u9519\u8bef<\/td><\/tr><tr><td>systemd + bash<\/td><td>\u6700\u7a33\u5065\u7684\u751f\u4ea7\u65b9\u5f0f<\/td><\/tr><\/tbody><\/table><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u7ed9\u4f60\u4e00\u4efd \u300a.NET Core \u9879\u76ee\u90e8\u7f72\u65f6\u81ea\u52a8\u68c0\u67e5\u5e76\u4fee\u590d\u7f3a\u5c11\u7684\u73af\u5883\u53d8\u91cf\u503c\u811a\u672c&#8230; <a class=\"more-link\" href=\"https:\/\/www.52runoob.com\/index.php\/2025\/12\/07\/net_core%e9%a1%b9%e7%9b%ae%e9%83%a8%e7%bd%b2%e6%97%b6%e8%87%aa%e5%8a%a8%e6%a3%80%e6%9f%a5%e5%b9%b6%e4%bf%ae%e5%a4%8d%e7%bc%ba%e5%b0%91%e7%9a%84%e7%8e%af%e5%a2%83%e5%8f%98%e9%87%8f%e5%80%bc%e8%84%9a\/\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[50],"tags":[],"class_list":["post-625","post","type-post","status-publish","format-standard","hentry","category-asp-net"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/625","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/comments?post=625"}],"version-history":[{"count":1,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/625\/revisions"}],"predecessor-version":[{"id":626,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/posts\/625\/revisions\/626"}],"wp:attachment":[{"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/media?parent=625"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/categories?post=625"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.52runoob.com\/index.php\/wp-json\/wp\/v2\/tags?post=625"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}