.NET Core 2.1应用程序是从VS2017发布的,而不是从命令行发布的?

时间:2019-05-07 17:58:31

标签: c# .net-core visual-studio-2017 publishing

我关闭了TreatWarningsAsErrors,因为在将自包含设置为true时,发布时一直出错。现在VS2017已成功发布,但是命令行dotnet publish仍然报告相同的错误。如何解决这个问题?

我收到的错误示例: 错误NU1605:检测到程序包降级:System.Runtime.InteropServices从4.3.0到4.1.0。直接从项目中引用该软件包,因此请选择其他版本。

VS2017发布实际有效的设置: enter image description here cmd行不起作用:

dotnet publish "c:\myproject.csproj" -f netcoreapp2.1 -c "Debug" -o "c:\users\me\dekstop\publish" --self-contained true -r win-x64

EDIT添加了csproj内容*

<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup Label="Globals">
    <SccProjectName>SAK</SccProjectName>
    <SccProvider>SAK</SccProvider>
    <SccAuxPath>SAK</SccAuxPath>
    <SccLocalPath>SAK</SccLocalPath>
    <Platforms>x64;x86</Platforms>
</PropertyGroup>

<PropertyGroup>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <EnableDefaultCompileItems>False</EnableDefaultCompileItems>
</PropertyGroup>

<ItemGroup>
    <Compile Include="..\..\GlobalInfo\GlobalAssemblyInfo.cs">
        <Link>Properties\GlobalAssemblyInfo.cs</Link>
    </Compile>
    <Compile Include="Configuration\CrossPlatformConfiguration.cs" />
    <Compile Include="Program.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
    <Compile Include="Registrations\SetupModule.cs" />
</ItemGroup>

<ItemGroup>
    <Reference Include="Autofac">
        <HintPath>..\..\packages\autofac\4.9.2\lib\netstandard2.0\Autofac.dll</HintPath>
    </Reference>
    <Reference Include="log4net">
        <HintPath>..\..\packages\log4net\2.0.8\lib\netstandard1.3\log4net.dll</HintPath>
    </Reference>
</ItemGroup>

<ItemGroup>
    <ProjectReference Include="..\..\proj1.csproj" />
    <ProjectReference Include="..\..\proj2.csproj" />
</ItemGroup>

<ItemGroup>
    <None Update="app.config">
        <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
</ItemGroup>

<PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <SignAssembly>true</SignAssembly>
    <AssemblyOriginatorKeyFile>..\..\_Keys\Private\MyXkey.snk</AssemblyOriginatorKeyFile>
    <AssemblyName>Test.Setup</AssemblyName>
    <RootNamespace>Test.Setup</RootNamespace>
    <DelaySign>false</DelaySign>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x86'">
    <OutputPath>..\..\Bin\x86\Debug\</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <OutputPath>..\..\Bin\x64\Debug\</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <OutputPath>..\..\Bin\x64\Release\</OutputPath>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x86'">
    <OutputPath>..\..\Bin\x86\Release\</OutputPath>
</PropertyGroup>

这里发生了什么变化,使VS2017可以发布可执行文件?

2 个答案:

答案 0 :(得分:1)

ProgrammerMan带我解决了这个问题,那就是添加

{{1}}

解决方案中每个项目的csproj。

答案 1 :(得分:0)

不是答案,而是一些最终可能有助于实现“真实”解决方案的信息...

我相信您会在VS2017中发现相同的NU1605错误,但不同之处在于它们被视为警告,因此发布成功完成。
发布后,您可以在“输出”窗口中看到警告-查看> 输出,然后显示来自以下版本的输出:构建

  • 我发现错误/警告链接到目标运行时(-r)等 而不是“便携式”(或空白)会导致它们。
  • 我已经更新到.NET Core 2.2.107,仍然可以使用它们。
  • 我的.NET Standard 2.0项目也是如此。
  • 我也通过添加相同的NoWarn建议使它们静音。