发布自包含的.NET Core应用程序

5

最近,我安装了带有.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 中创建自包含应用程序?也许应该在 csproj 中指定 runtime 部分(就像在 json 中所需的那样)?
1个回答

5

我相信,您应该按照以下步骤执行:

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>

上述是指定你想要的核心/自包含功能的正确方式。你可以在这里找到很多相关信息: 这里

构建失败(指定win10-x64标志时,没有-它是好的) - nuget包中没有一个被识别。 - pwas
编译成功了,但运行不起来: `Microsoft (R) Build Engine version 15.1.458.808 Copyright (C) Microsoft Corporation. All rights reserved. SquadPlanning -> C:\Users\patry\Documents\Visual Studio 2017\Projects\SquadPlanning\src\SquadPlanning\bin\Debug\netcoreapp1.0\SquadPlanning.dll`仍然是dll文件。 - pwas
使用的命令:dotnet build -r win10-x64dotnet publish -r win10-x64 - pwas
@pwas你看看我给你发的网站了吗? - Greg
是的。但文档介绍的是 .net core 预览版 3,问题出现在预览版 4 上。这是我在 GitHub 上创建的问题:https://github.com/dotnet/cli/issues/5105 - pwas

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接