Skip to content

Running dotnet build on a project that targets both net451 and netcoreapp1.0 fails #423

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
prafullbhosale opened this issue Nov 24, 2016 · 3 comments
Assignees
Labels
Milestone

Comments

@prafullbhosale
Copy link

Steps to reproduce

Run dotnet restore and dotnet build on the below project

<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" />
  
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFrameworks>net451;netcoreapp1.0</TargetFrameworks>
    <RunTimeIdentifier Condition="'$(TargetFramework)' == 'net451'">win7-x86</RunTimeIdentifier>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**\*.cs" />
    <EmbeddedResource Include="**\*.resx" />
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
    <PackageReference Include="Microsoft.NET.Sdk">
      <Version>1.0.0-alpha-20161104-2</Version>
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.CommandLineUtils">
      <Version>1.0.1</Version>
    </PackageReference>
  </ItemGroup>
  <ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp1.0' ">
    <PackageReference Include="Microsoft.NETCore.App">
      <Version>1.0.1</Version>
    </PackageReference>
    <PackageReference Include="Microsoft.NET.Sdk">
      <Version>1.0.0-alpha-20161104-2</Version>
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
  </ItemGroup>
  
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
using Microsoft.Extensions.CommandLineUtils;
using System;

class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Hello World!");
        var app = new CommandLineApplication();
    }
}

Expected behavior

Build succeeds.

Actual behavior

Error

Program.cs(1,17): error CS0234: The type or namespace name 'Extensions' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) [C:\Users\prbhosal\Documents\Visual Studio 2017\Projects\ConsoleApp1\ConsoleApp1\ConsoleApp1.csproj]

Workaround

Run dotnet msbuild /t:Restore /p:TargetFramework=net451 and then run dotnet build

Environment data

dotnet --info output:

.NET Command Line Tools (1.0.0-preview4-004117)

Product Information:
Version: 1.0.0-preview4-004117
Commit SHA-1 hash: 923320b

Runtime Environment:
OS Name: Windows
OS Version: 10.0.14393
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\1.0.0-preview4-004117

cc @mlorbetske @pranavkm

@srivatsn srivatsn added the Bug label Nov 29, 2016
@srivatsn srivatsn added this to the 1.0 RC3 milestone Nov 29, 2016
@natemcmaster
Copy link
Contributor

+1. Command line restore/build is the only way to build. Restore/build within VS2017 breaks. With CLI 1.0.0-preview4-004233, the error is:

'C:\dev\TestProj\obj\project.assets.json' doesn't have a target for '.NETFramework,Version=v4.5.1/win7-x64'. Ensure you have restored this project for TargetFramework='net451' and RuntimeIdentifier='win7-x64'. TestProj C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets 119

@prafullbhosale
Copy link
Author

Just in case anybody else hits this, there is another simple workaround for this. Just need to flip the condition to exclude the RuntimeIdentifier property from all other TFMs

<RunTimeIdentifier Condition="'$(TargetFramework)' != 'netcoreapp1.0'">win7-x86</RunTimeIdentifier>

@srivatsn srivatsn assigned nguerrera and unassigned dsplaisted Jan 7, 2017
@srivatsn srivatsn modified the milestones: 1.0 RC3, 1.0 RTM Jan 13, 2017
@nguerrera
Copy link
Contributor

Closing as duplicate of #396, the plan for which will fix this.

mmitche pushed a commit to mmitche/sdk that referenced this issue Jun 5, 2020
Workaround for netstandard 3.0 to add extensions to app in the web.config
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants