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

C# .NET Core 2.1应用程序从VS2017发布,但不从命令行发布?,c#,.net-core,visual-studio-2017,publishing,C#,.net Core,Visual Studio 2017,Publishing,我关闭了TreatWarningAsErrors,因为当self-contained设置为true时,我在发布时不断出现错误。现在VS2017发布成功,但命令行dotnet publish仍报告相同的错误。如何解决这个问题 我收到的错误示例: 错误NU1605:检测到包降级:System.Runtime.InteropServices从4.3.0降级到4.1.0。直接从项目中引用软件包,因此请选择其他版本。 VS2017发布实际有效的设置: 无效的cmd行: dotnet publish "c:

我关闭了TreatWarningAsErrors,因为当self-contained设置为true时,我在发布时不断出现错误。现在VS2017发布成功,但命令行dotnet publish仍报告相同的错误。如何解决这个问题

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

VS2017发布实际有效的设置: 无效的cmd行:

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\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>

萨克
萨克
萨克
萨克
x64;x86
假的
假的
属性\GlobalAssemblyInfo.cs
..\..\packages\autofac\4.9.2\lib\netstandard2.0\autofac.dll
..\..\packages\log4net\2.0.8\lib\netstandard1.3\log4net.dll
保存最新
Exe
netcoreapp2.1
真的
..\..\\u Keys\Private\MyXkey.snk
测试设置
测试设置
假的
..\..\Bin\x86\Debug\
..\..\Bin\x64\Debug\
..\..\Bin\x64\Release\
..\..\Bin\x86\Release\


这里发生了什么不同的事情,使得VS2017能够发布可执行文件?

ProgrammerMan让我找到了解决方案,即添加

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

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

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

我相信您会在VS2017中发现相同的NU1605错误,但区别在于它们被视为警告,因此发布将成功完成。
发布后,您可以在输出窗口-View>Output中看到警告,然后显示输出自:Build

  • 我发现错误/警告链接到目标运行时(-r)和任何东西 除“便携式”(或空白)之外的其他设备将导致这些问题
  • 我已经更新到了.NETCore2.2.107,现在仍然可以使用它们
  • 我的.NET标准2.0项目也得到了同样的结果
  • 我还添加了相同的NoWarn建议,使他们保持沉默

当你说它不起作用时,你是什么意思?您是否收到错误消息,如果收到,是什么消息?我们需要更多的信息。错误信息在我上面的问题中以粗体显示抱歉,我错过了。您可以发布项目文件的内容吗?添加了csproj contentsit,如果我删除--self-contain和-r win-x64开关,也不会从cmd行报告任何错误。不知道为什么,因为当VisualStudio执行此操作时,这些都存在!事实上是这样的