【问题标题】:Publishing self-contained app .NET Core application发布自包含应用程序 .NET Core 应用程序
【发布时间】:2016-12-20 20:20:31
【问题描述】:

最近,我安装了带有 .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 中一样)?

【问题讨论】:

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


    【解决方案1】:

    我相信,你应该做到以下几点:

    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

    【讨论】:

    • 构建失败(指定了 win10-x64 标志,没有 - 没关系) - 没有识别出 nuget 包。
    • 设法编译,但没有运气:Microsoft (R) Build Engine version 15.1.458.808 Copyright (C) Microsoft Corporation. All rights reserved. SquadPlanning -&gt; C:\Users\patry\Documents\Visual Studio 2017\Projects\SquadPlanning\src\SquadPlanning\bin\Debug\netcoreapp1.0\SquadPlanning.dll Still dll.
    • 使用的命令:dotnet build -r win10-x64 和 `dotnet publish -r win10-x64`。
    • @pwas 你看看我链接的那个网站?
    • 是的。但是 Docs 讲述了 .net core preview 3,问题出现在 preview 4。这是我在 github 上创建的问题:github.com/dotnet/cli/issues/5105
    猜你喜欢
    • 2019-04-28
    • 2018-07-30
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    • 2020-09-10
    • 2021-11-06
    • 1970-01-01
    • 2022-01-24
    相关资源
    最近更新 更多