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

.NET Core 2.1 app publishes from VS2017 but not command line?

我关闭了 TreatWarningsAsErrors,因为在独立设置为 true 的情况下发布时我总是遇到错误。现在VS2017发布成功,但是命令行dotnet publish还是报同样的错误。如何解决这个问题?

我收到的错误示例: error NU1605:检测到包降级:System.Runtime.InteropServices 从 4.3.0 到 4.1.0。直接从项目中引用包,因此 select 不同的版本。

VS2017 发布实际有效的设置: 不起作用的命令行:

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

编辑添加了 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.9.2\lib\netstandard2.0\Autofac.dll</HintPath>
    </Reference>
    <Reference Include="log4net">
        <HintPath>..\..\packages\log4net.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 发布可执行文件?

ProgrammerMan 引导我找到解决方案,即添加

<NoWarn>$(NoWarn);NU1605</NoWarn>

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

不是答案,而是一些最终可能有助于 'real' 解决方案的更多信息...

我相信你会在 VS2017 中发现相同的 NU1605 错误,但不同之处在于它们被视为警告,因此发布成功完成。
发布后,您可以在输出 window - View > Output 中看到警告,然后 Show 输出来自:构建.

  • 我发现 errors/warning 链接到目标运行时 (-r) 和任何东西 除了 'Portable'(或空白)以外的其他将导致它们。
  • 我已经更新到 .NET Core 2.2.107 并且仍然可以使用它们。
  • 我的 .NET Standard 2.0 项目也一样。
  • 我还通过添加相同的 NoWarn 建议将它们静音。