dotnet build doesn't resolve package references correctly for old style projects
See original GitHub issueSteps 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.
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:
- Created 3 years ago
- Reactions:4
- Comments:12 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@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.
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