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

时间:2016-12-20 20:20:31

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

最近,我安装了VS 2017 RC与.NET Core Preview 4 SDK。 在新的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 个答案:

答案 0 :(得分:4)

我相信,你应该做以下事情:

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

相关问题