asp.net-core - 发布自包含应用程序 .NET Core 应用程序

标签 asp.net-core .net-core

最近,我安装了带有 .NET Core Preview 4 SDK 的 VS 2017 RC。
在新的 SDK 中,没有 project.json , 仅 csproj文件:

<PropertyGroup>
   <OutputType>winexe</OutputType>
   <TargetFramework>netcoreapp1.0</TargetFramework>
     <PreserveCompilationContext>true</PreserveCompilationContext>
</PropertyGroup

现在的问题是,dotnet publish输出 dll ,不是 exe文件。
我试过运行 dotnet publish -r win10-x64但它甚至无法编译。

如何在 dotnet 1.1 Preview 中制作自包含应用程序?
也许我应该指定 runtime csproj 中的部分(就像 json 中要求的那样)?

最佳答案

我相信,您应该执行以下操作:

dotnet build -r win10-x64
dotnet publish -c release -r win10-x64

您需要首先构建它。

要表示的另一件事是 .csproj 和 project.json 功能几乎相同。所以 .csproj 应该被配置:
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp1.0</TargetFramework>
    <VersionPrefix>1.0.0</VersionPrefix>
    <DebugType>Portable</DebugType>
    <RuntimeIdentifiers>win10-x64;osx.10.11-x64</RuntimeIdentifiers>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="**\*.cs" />
    <EmbeddedResource Include="**\*.resx" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.NETCore.App">
      <Version>1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Newtonsoft.Json">
      <Version>9.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Sdk">
      <Version>1.0.0-alpha-20161102-2</Version>
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
  </ItemGroup>

  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

以上是指定您所追求的核心/自包含功能的正确方法。你可以在上面找到很多信息here .

关于asp.net-core - 发布自包含应用程序 .NET Core 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41250636/

相关文章:

c# - 使用默认路由的属性路由

entity-framework - 与Entity Framework Core一起使用

c# - 发布到 Azure 解决方法 : trying to understand compiled files to upload them by FTP

c# - 从 ServiceCollection 获取 IConfiguration

c# - 使用通过 .NET Core 和 Xamarin 从 IL 编译的程序集

.net - FileLoadException : Could not load file or assembly System.运行时,版本= 4.2.0.0

asp.net-core - "The library ' hostpolicy.dll ' required"如果从部署文件夹运行,但emitEntryPoint为true

.net - 仅在发布 ASP.NET 5 Web 应用程序时执行 Gulp 任务

c# - asp.net 标签助手不工作

asp.net-core - 在 VSCode 中运行 ASP.NET Core Web 应用程序时如何修复 HTTPS 证书错误