question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet build doesn't resolve package references correctly for old style projects

See original GitHub issue

Steps to reproduce

Dotnet build does not resolve package references in old style projects, but restore seems to be done fine. I tried also several variations like dotnet msbuild /t:restore;build etc. All lead to the same build errors.

PackageReferenceBugDemo.zip

Project file

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{C27219F1-6C86-4D9C-B9C3-4B01B5D9879B}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>PackageReferenceBugDemo</RootNamespace>
    <AssemblyName>PackageReferenceBugDemo</AssemblyName>
    <TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
    <FileAlignment>512</FileAlignment>
    <Deterministic>true</Deterministic>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Nunit" Version="2.5.10.11092"/>
    
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Xml.Linq" />
    <Reference Include="System.Data.DataSetExtensions" />
    <Reference Include="Microsoft.CSharp" />
    <Reference Include="System.Data" />
    <Reference Include="System.Net.Http" />
    <Reference Include="System.Xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Class1.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>

  </ItemGroup>
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

Directory contents:

see attachment

Command line

dotnet build

Expected behavior

The build runs fine

Actual behavior

The nunit package reference doesn’t get resolved

Environment data

dotnet msbuild //version

Microsoft (R)-Build-Engine, Version 16.4.0+e901037fe f▒r .NET Core
Copyright (C) Microsoft Corporation. Alle Rechte vorbehalten.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:4
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
TFTomSuncommented, Apr 14, 2020

@rainersigwald That’s why I wonder. The projects I tried to build don’t use any features that couldn’t be built by a similar SDK style project format with for example TargetFramework net48. They don’t contain WCF, WF, ASP.NET 2/4.

That means, technically everything is in place to built these kind of projects with the dotnet sdk. Just because they have the old style format, they can’t be built via dotnet build. A possibility to develop dotnet sdk based CI/CD solutions that work with legacy code as well, would be nice, even if dotnet build would fallback to an installed build tools instance.

But I understand now, that the suggested migration path is to upgrade to sdk style first before you can use the dotnet cli for building the projects, it’s just difficult to achieve that in large code bases.

0reactions
bz-wowcommented, Dec 16, 2021

I wish I could build a solution that contains both types of projects with it.

You can, but you have to use MSBuild.exe (from VS or VS build tools).

Use msbuild directly, it shows error “C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\NuGet\16.0\Microsoft.NuGet.targets(1 98,5): error : Your project file doesn’t list ‘win’ as a “RuntimeIdentifier”. You should add ‘win’ to the “RuntimeIdent ifiers” property in your project file and then re-run NuGet restore.” PS: this should be a nuget.exe bug according to https://github.com/NuGet/Home/issues/10590. Earlier nuget version like 5.4.0 is ok.

Not sure if any other issue appears if above one is fixed.

Had to run nuget (like v5.4, latest version has bug mentioned avove) restore and then msbuild to make it built.

Additionally, this limition and solution are not mentioned in official doc - https://docs.microsoft.com/en-us/nuget/consume-packages/package-references-in-project-files

Read more comments on GitHub >

github_iconTop Results From Across the Web

Project reference not resolved when running dotnet build
I found a workaround, so I'm posting it here and I'm going with it for now, but I don't think it's a good...
Read more >
Troubleshoot .NET Framework targeting errors
This article provides resolutions for MSBuild errors that might occur because of reference issues.
Read more >
Troubleshoot broken references - Visual Studio
To fix a broken project reference, correct the reference path by following these steps: In Solution Explorer, right-click your project node, ...
Read more >
Troubleshooting NuGet Package Restore in Visual Studio
This error occurs when you attempt to build a project that contains references to one or more NuGet packages, but those packages are...
Read more >
MSBuild reference for .NET SDK projects
This page is a reference for the MSBuild properties and items that you can use to configure .NET projects. Note. This page is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found