发布.NET CORE 2 API项目,而无需Microsift DLL



当我发布我的Net Core Project

<Project Sdk="Microsoft.NET.Sdk.Web">
  <PropertyGroup>
    <Authors>Arthur Vaverko</Authors>
    <Company>Home</Company>
    <Product>MyApi</Product>
    <PackageId>MyApi</PackageId>
    <Version>1.0.0.0</Version>
    <AssemblyVersion>1.0.0.0</AssemblyVersion>
    <FileVersion>1.0.0.0</FileVersion>
    <NeutralLanguage>en</NeutralLanguage>
    <Description>My package</Description>
    <Copyright>Copyright © 2017</Copyright>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <IsTransformWebConfigDisabled>true</IsTransformWebConfigDisabled>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Home.MyPackage" Version="1.7.0" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.2"/>
    <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0"/>
  </ItemGroup>
</Project>

运行以下

dotnet publish -o build

我得到以下DLL的列表...(部分...(

..... de es fr it ja kalturaclient.net.core.dll ko log4net.config log4nnet.dll microsoft.ai.dependendencyCollector.dll Microsoft.ApplicationInsights.aspnetcore.dll Microsoft.ApplicationInsights.dll microsoft.aspnetcore.antiforgery.dll Microsoft.aspnetcore.applicationinsights.hostingstartup.dl microsoft.aspnetcore.authentication.abstractions.dll microsoft.aspnetcore.authentication.cookies.dll microsoft.aspnetcore.authentication.core.dll Microsoft.aspnetcore.authentication.dll microsoft.aspnetcore.authentication.facebook.dll microsoft.aspnetcore.authentication.google.dll microsoft.aspnetcore.authentication.jwtbearer.dll Microsoft.aspnetcore.authentication.microsoftaccount.dll microsoft.aspnetcore.authentication.oauth.dll microsoft.aspnetcore.authentication.openidconnect.dll microsoft.aspnetcore.authentication.twitter.dll microsoft.aspnetcore.authorization.dll microsoft.aspnetcore.authorization.policy.dll microsoft.aspnetcore.azureappservices.hostingstartup.dll microsoft.aspnetcore.azureappservicesIntegration.dll microsoft.aspnetcore.cookiepolicy.dll microsoft.aspnetcore.cors.dll microsoft.aspnetcore.cryptography.internal.dll microsoft.aspnetcore.cryptography.keyderivation.dll microsoft.aspnetcore.dataprotection.abstractions.dll microsoft.aspnetcore.dataprotection.azurestorage.dll microsoft.aspnetcore.dataprotection.dll microsoft.aspnetcore.dataprotection.extensions.dll microsoft.aspnetcore.diagnostics.abstractions.dll Microsoft.aspnetcore.diarostics.dll microsoft.aspnetcore.diagnostics.entityframeworkcore.dll microsoft.aspnetcore.dll microsoft.aspnetcore.hosting.abstractions.dll microsoft.aspnetcore.hosting.dll microsoft.aspnetcore.hosting.server.abstractions.dll microsoft.aspnetcore.html.abstractions.dll Microsoft.aspnetcore.http.abstractions.dll microsoft.aspnetcore.http.dll microsoft.aspnetcore.http.extensions.dll Microsoft.aspnetcore.http.features.dll Microsoft.aspnetcore.httpoverrides.dll Microsoft.aspnetcore.Identity.dll Microsoft.aspnetcore.Identity.EntityFrameWorkcore.dll Microsoft.aspnetcore.jsonpatch.dll microsoft.aspnetcore.localization.dll Microsoft.aspnetcore.localization.Routing.dll Microsoft.aspnetcore.middlewareanalysis.dll microsoft.aspnetcore.mvc.abstractions.dll microsoft.aspnetcore.mvc.apiexplorer.dll microsoft.aspnetcore.mvc.core.dll microsoft.aspnetcore.mvc.cors.dll microsoft.aspnetcore.mvc.dataannotations.dll Microsoft.aspnetcore.mvc.dll Microsoft.aspnetcore.mvc.formatters.json.dll microsoft.aspnetcore.mvc.formatters.xml.dll Microsoft.aspnetcore.mvc.localization.dll microsoft.aspnetcore.mvc.razor.dll microsoft.aspnetcore.mvc.razor.extensions.dll microsoft.aspnetcore.mvc.razorpages.dll Microsoft.aspnetcore.mvc.taghelpers.dll microsoft.aspnetcore.mvc.viewfeatures.dll microsoft.aspnetcore.nodeservices.dll microsoft.aspnetcore.owin.dll microsoft.aspnetcore.razor.dll microsoft.aspnetcore.razor.language.dll microsoft.aspnetcore.razor.runtime.dll microsoft.aspnetcore.responsecaching.abstractions.dll ....

我如何仅发布我需要的DLL,因为目标计算机包含ISS DotNetCore.2.0.5-WindowsHosting,如果需要,我宁愿同时安装.NET Core SDK,而不是每次发布一个〜48MB项目。

<</p>

查看dotnet publish的支持页面,它说有可能的选项:

dotnet publish [<PROJECT>] [-c|--configuration] 
[-f|--framework] [--force] [--manifest] 
[--no-dependencies] [--no-restore] [-o|--output] 
[-r|--runtime] [--self-contained] [-v|--verbosity] 
[--version-suffix]

指定运行时,--self-contained的默认值是正确的。

--self-contained设置为真实,隐式或显式时,它将其发布框架文件以使其形成 - 如词所建议的 - "自我包含"。当您将其设置为false时,它将仅发布"您的" dll。

可以在此处找到有关命令的更多信息:https://learn.microsoft.com/en-us/dotnet/core/core/tools/dotnet-publish?tabs=netcore2x

您发现"依赖框架的部署"与amp;在这里:https://learn.microsoft.com/en-us/dotnet/core/deploying/index


因此,如果您在已发布的文件夹中看到运行时软件包,则有2个可能性。

有2个可能性。

  1. 您正在使用-r | --runtime <RUNTIME>选项指定运行时
  2. 您明确将--self-contained设置为True

您可以尝试dotnet Publish -c Release

最新更新