Mark Nadig
Mark Nadig

Reputation: 5136

dotnet build failing with "The type or namespace name... does not exist" in solution with netstandard2.0 and 4.7.2

I have a solution that contains two projects, one targeting 4.7.2 and one targeting netstandard2.0. I can build the solution just fine within Visual Studio 2019. However, when I run dotnet build MySolution.sln it fails with a number of "Type of namespace ... does not exist" errors related to nuget packages referenced in that project.

src\MyService\Authenticator.cs(2,17): error CS0234: The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [src\MyService\MyService.csproj]
src\MyService\Authenticator.cs(5,23): error CS0234: The type or namespace name 'Json' does not exist in the namespace 'System.Net.Http' (are you missing an assembly reference?) [src\MyService\MyService.csproj]
src\MyService\Authenticator.cs(7,7): error CS0246: The type or namespace name 'Flurl' could not be found (are you missing a using directive or an assembly reference?) [src\MyService\MyService.csproj]

All of the source is available at https://github.com/marknadig/TestBuild.

The first project "MyService" is a .net 4.7.2 class library project.

<?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>{3C5D1FFA-5620-4BE0-B79F-801DAD8B176A}</ProjectGuid>
    <OutputType>Library</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>MyService</RootNamespace>
    <AssemblyName>MyService</AssemblyName>
    <TargetFrameworkVersion>v4.7.2</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>
    <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="Authenticator.cs" />
</ItemGroup>
<ItemGroup>
    <PackageReference Include="Flurl.Http">
    <Version>3.2.0</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.Extensions.Logging">
    <Version>5.0.0</Version>
    </PackageReference>
    <PackageReference Include="System.Net.Http.Json">
    <Version>5.0.0</Version>
    </PackageReference>
    <PackageReference Include="System.Text.Json">
    <Version>5.0.2</Version>
    </PackageReference>
</ItemGroup>
<ItemGroup>
    <ProjectReference Include="..\AuthenticatorService\AuthenticatorService.csproj">
    <Project>{cce9bb31-d3e8-4573-8e3a-4ce0bf793fa1}</Project>
    <Name>AuthenticatorService</Name>
    </ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

As you can see the MyService project references AuthenticatorService project which target "netstandard20".

<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
    <TargetFrameworks>netstandard2.0</TargetFrameworks>
    <AssemblyName>AuthenticatorService</AssemblyName>
    <RootNamespace>AuthenticatorService</RootNamespace>
</PropertyGroup>
<ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
</ItemGroup>
</Project>

dotnet --version reports 5.0.402

How can I get dotnet build to build?

Upvotes: 1

Views: 2594

Answers (1)

Mark Nadig
Mark Nadig

Reputation: 5136

Turns out "The dotnet cli does not support old style csproj files and does not support windows desktop projects, which is why it fails for you."

https://github.com/dotnet/sdk/issues/8931#issuecomment-350167706

This works:

msbuild /t:restore TestBuild.sln
msbuild TestBuild.sln

Upvotes: 3

Related Questions