发布没有Microsift dll的.net core 2 Api项目

时间:2018-02-24 19:02:08

标签: asp.net-core asp.net-core-2.0

当我发布我的网络核心项目时

<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   log4net.dll Microsoft.AI.DependencyCollector.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.Diagnostics.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核心sdk,而不是每次都发布一个~48Mb项目。 / p>

2 个答案:

答案 0 :(得分:2)

查看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的默认值为true。

--self-contained被隐式或显式地设置为true时,它会发布框架文件来制作它 - 正如单词所暗示的那样 - &#34;自包含&#34;。当您将其设置为false时,它只会发布&#34;您的&#34;的DLL。

有关命令的更多信息,请访问:https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-publish?tabs=netcore2x

你发现&#34;依赖于框架的部署&#34; &安培; &#34;自包含部署&#34;在这里:https://docs.microsoft.com/en-us/dotnet/core/deploying/index

因此,如果您在已发布的文件夹中看到运行时包,那么就会遇到当前问题,有两种可能性。

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

答案 1 :(得分:0)

您可以尝试使用dotnet发布-c Release