最近,我安装了带有 .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/