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

I turned OFF the TreatWarningsAsErrors, as i kept getting errors when publishing while self-contained is set to true. Now VS2017 publishes successfully, but the command line dotnet publish still reports the same errors. How can fix this?

Example of the errors i receive: error NU1605: Detected package downgrade: System.Runtime.InteropServices from 4.3.0 to 4.1.0. Reference the package directly from the project so select a different version.

VS2017 Publish settings that actually works: enter image description here cmd line that doesn't work:

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

EDIT added csproj contents*

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

What is happening differently here that allows VS2017 to publish the executable?

Upvotes: 1

Views: 392

Answers (2)

WantStuff
WantStuff

Reputation: 71

Not an answer, but some more information that may eventually help towards a 'real' solution...

I believe you will find the same NU1605 errors in VS2017, but the difference is they are treated as warnings so the publish completes successfully.
After publishing you can see the warnings in the Output window - View > Output and then Show output from: Build.

  • I find the errors/warning are linked to the target runtime (-r) and anything other than 'Portable' (or blank) will cause them.
  • I have updated to .NET Core 2.2.107 and still get them.
  • I also get the same with my .NET Standard 2.0 project.
  • I have also muted them by adding the same NoWarn suggestion.

Upvotes: 0

ProgrammerMan led me to the solution, which was to add

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

to the csproj of each project in the solution.

Upvotes: 2

Related Questions