dotnet / standard

This repo is building the .NET Standard
3.07k stars 428 forks source link

Error CS0012 The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. #391

Closed valeriob closed 7 years ago

valeriob commented 7 years ago

Hi, i'm using vs 2017 15.3 Preview 2. Create a netstandard2 project, a .net 4.6.1 project, add some reference to both, and reference netstandard2 library from .net 4.6.1 one. Attached the solution with the repro.

Thanks Netstandard2 referenced by net461.zip

joperezr commented 7 years ago

I believe you are missing a reference to NETStandard.Library.NETFramework package. You can find it here

For now you have to manually add a reference to this package which can be annoying, but in the future we are planning on the tooling doing this for you. Let me know if that works for you.

valeriob commented 7 years ago

Hi, i added the reference to NETStandard.Library.NETFramework in the Net461 project but still does not work, check out my attachment.

Netstandard2 referenced by net461.zip

dasMulli commented 7 years ago

Looks like NuGet doesn't emit the necessary binding redirects to the .net framework library project since it is both a library and doesn't have an app.config.

You could try to add NETStandard.Library.NETFramework to the executing project you are using the library from or add this to the csproj file of the .net library:

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>
valeriob commented 7 years ago

Hi @dasMulli, i added

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup> 

to the net461 project but nothing changes. I thought that interoperability between netFramework vs netstandard was a priority on vs 2017 15.3, how can be possible i encounter this problem ?

Thanks again

weshaggard commented 7 years ago

I thought that interoperability between netFramework vs netstandard was a priority on vs 2017 15.3, how can be possible i encounter this problem ?

It is definitely a priority but it is still a work in progress. Until it is complete you need to add the reference to NETStandard.Library.NETFramework into your net461 project. With that I was able to get past this error on your sample project.

However I quickly hit an error with the Raven Client nuget package.

1>D:\git\tests\samples\netfx_ns\Net461\Class1.cs(15,25,15,44): error CS0012: The type 'IDocumentStore' is defined in an assembly that is not referenced. You must add a reference to assembly 'Raven.Client.Lightweight, Version=3.5.3.0, Culture=neutral, PublicKeyToken=null'.

Which is because the net45 assembly identity of Raven.Client.Lightweight is different from the netstandard version. The net45 has a PublicKeyToken and the netstandard one doesn't. That appears to be a bug with RavenDB package.

valeriob commented 7 years ago

Hi @weshaggard i was using the wrong package ! I added the reference to NETStandard.Library instead of NETStandard.Library.NETFramework i did not know there where many of them. Then i'll ask the library author to fix that other problem. Thanks again

gerektoolhy commented 7 years ago

FYI, Not sure if this is related, but perhaps some will find this useful.

net461 framework with aspnetcore. Was getting similar exceptions:

error CS0518: Predefined type 'System.Object' is not defined or imported
error CS0518: Predefined type 'System.String' is not defined or imported
error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
error CS0518: Predefined type 'System.Void' is not defined or imported
<...>\Views\Home\Index.cshtml(2,5): error CS0012: The type 'ViewDataDictionary<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.

This was due to a wrong SDK. Updated to <Project Sdk="Microsoft.NET.Sdk.Web"> from <Project Sdk="Microsoft.NET.Sdk"> and issue is gone. Hope someone will find this useful, as it took me hours to drill down to this.

ManfredLange commented 7 years ago

Package NETStandard.Library.NETFramework has been deprecated according to this if you have the released .NET Core SDK 2.0 installed.

Adding the propertyGroup with settings to generate the binding redirects seems to solve the problem with Visual Studio 2017 (15.3). However, building the same project with msbuild in a script fails with "error CS0012: the type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51' " Also, instead of 'Object' it may say 'Action<>' in the error message.

Looks as if Visual Studio 2017 is not using the same set of msbuild tools/tasks ad the msbuild you run from the command line. Any suggestion how to confirm the versions either way?

daveh101 commented 7 years ago

I am also coming across this issue with VS 2017 15.4 Preview 1, and a UWP project targeted to Windows 10 Build 16267.

I have just installed the .NET Standard 2.0.2 SDK to fix an issue with not being able to use the .NET Standard project with a UWP project - but now have run into the above problem.

Guessing that means this issue hasn't been completely fixed?

weshaggard commented 7 years ago

Looks as if Visual Studio 2017 is not using the same set of msbuild tools/tasks ad the msbuild you run from the command line. Any suggestion how to confirm the versions either way?

@ManfredLange What version of msbuild are you using from the command line? Be sure to be running from a VS 2017 dev command prompt.

I have just installed the .NET Standard 2.0.2 SDK

@daveh101 what do you mean by that SDK? I don't know of any .NET Standard SDK? Are you talking about the .NET Core SDK? If so I don't think there is a 2.0.2 version of that yet.

daveh101 commented 7 years ago

@weshaggard I have upgraded my Visual Studio to the latest preview version as suggested in this post about .NET Standard 2.0 & UWP

https://blogs.msdn.microsoft.com/dotnet/2017/08/25/uwp-net-standard-2-0-preview

After doing so, I was still getting an error like this:

error : Project ‘.csproj’ targets ‘.NETStandard,Version=v2.0’. It cannot be referenced by a project that targets ‘UAP,Version=v10.0.16267’

In the comments, there is a fix that says .NET Standard SDK 2.0.2 - https://aka.ms/ns2x64 - or - https://aka.ms/ns2x86

Before installing the above it wouldn't even attempt to build. Now, it does try to build but I get the issue this thread.

Hope that helps

weshaggard commented 7 years ago

@daveh101 I see I'm not even sure which SDK that is but I believe it is the .NET Core SDK. At any rate while this is a similar error it is a unique issue for UWP can you please file a new issue for this with the information.

cc @joperezr @nattress

ManfredLange commented 7 years ago

@weshaggard Our build script is a powershell script that we run from a regular powershell terminal. The msbuild version we use is the one located at: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0

We haven't use the dev command prompt for many years. Instead we opted for a powershell script that cleans up the environment, builds the solution, deploys the solution (locally or build machine), then executes the test suite and finally reports the result. That approach is working very well across multiple products/companies and has been for several years now.

Occasionally, for diagnosing issues we sometimes switch to the one that is located at C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0

However, the latter is only available on a box with VS 2017 Professional Edition installed. On our build machines we only have the build tools available. This means that when we use the one that comes with VS 2017 Professional, we have 9 target files more. All other files are identical. As per the file properties the file version of msbuild.exe is "15.3.409.57025" and the product version is "15.3.409+gc1de301405".

Note that we haven't updated to the preview of VS 2017, 15.4 yet because of lack of time.

Meanwhile I observed this: If a ns2.0 assembly uses a net461 nuget package, that's fine (other than a warning if the nuget package does not target netstandard 2.0 or lower). If a ns2.0 project references a net461 project, that is a problem and by the looks of it not a tested scenario for VS 2017 version 15.3. I have not found a solution/workaround for the latter. A net461 project can reference a ns2.0 project without problem. Also a net461 project can make use of the nuget packages we use without issues as usually all of those packages also have a target that works for net461. So it appears that (in our environment) we need to distinguish between nuget packages (work fine so far) and referenced projects (problematic depending on the combination).

Note that we have a solution with 50+ projects, so it would be great to be able to mix net461 and ns2,0 projects so that we can incrementally move from net461 to ns2.0. The alternative is not viable for a production system with continuous delivery in my opinion.

weshaggard commented 7 years ago

@ManfredLange I'm not actually sure that referencing a net461 project from an ns20 project is fully working/supported. I've not personally tried that direction. I don't know a lot about all the different msbuild and VS tool combinations so I going to suggest you file a new issue at https://github.com/dotnet/project-system as they are the C# VS experts.

zidad commented 7 years ago

I've installed all the latest updates for the build tools and visual studio, and I also can't build from the command line. from Visual Studio 2017 it works fine. dotnet --version: 2.0.0

When I build a (very simple) project:


C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018: The "ResolvePackageDependencies" task failed unexpectedly.\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Message
\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                                      
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018: System.MissingMethodException: Method not found: 'System.Collections.Generic.IList`1<NuGet.Packaging.Core.PackageDependency> NuG
t.ProjectModel.LockFileTargetLibrary.get_Dependencies()'.\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                      
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.GetPackageDependencies(LockFileTargetLibrary package, String targetNa
e, Dictionary`2 resolvedPackageVersions, HashSet`1 transitiveProjectRefs)\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                      
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.GetPackageAndFileDependencies(LockFileTarget target)\r [C:\Projects\P
card\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                 
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.RaiseLockFileTargets()\r [C:\Projects\MyCompany\MyProduct\MyCompany.Mik
n\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                               
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.ExecuteCore()\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany
MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                        
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany
MyProduct.Messages.csproj]                                                                                                                                                                                                                                              
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()\r [C:\Projects\MyCompany\picar
.citrus\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                            
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__25.MoveNext() [C:\Projects\MyCompany\MyProduct\MyCompany.Mik
n\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                               
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018: The "ResolvePackageDependencies" task failed unexpectedly.\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Message
\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                                      
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018: System.MissingMethodException: Method not found: 'System.Collections.Generic.IList`1<NuGet.Packaging.Core.PackageDependency> NuG
t.ProjectModel.LockFileTargetLibrary.get_Dependencies()'.\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                      
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.GetPackageDependencies(LockFileTargetLibrary package, String targetNa
e, Dictionary`2 resolvedPackageVersions, HashSet`1 transitiveProjectRefs)\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                      
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.GetPackageAndFileDependencies(LockFileTarget target)\r [C:\Projects\P
card\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                 
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.RaiseLockFileTargets()\r [C:\Projects\MyCompany\MyProduct\MyCompany.Mik
n\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                               
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.ResolvePackageDependencies.ExecuteCore()\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany
MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                        
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute()\r [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany
MyProduct.Messages.csproj]                                                                                                                                                                                                                                              
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()\r [C:\Projects\MyCompany\picar
.citrus\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                            
C:\Program Files\dotnet\sdk\1.0.4\Sdks\Microsoft.NET.Sdk\build\Microsoft.PackageDependencyResolution.targets(154,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__25.MoveNext() [C:\Projects\MyCompany\MyProduct\MyCompany.Mik
n\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                               
C:\Users\Wiebe\AppData\Local\Temp\.NETCoreApp,Version=v2.0.AssemblyAttributes.cs(4,20): error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?) [C:\Projects\MyCompany\MyProduct\Pica
d.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                         
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(10,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(11,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(12,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(13,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(14,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(15,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(16,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(17,12): error CS0246: The type or namespace name 'System' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct
Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                                                              
C:\Users\Wiebe\AppData\Local\Temp\.NETCoreApp,Version=v2.0.AssemblyAttributes.cs(4,71): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj] 
C:\Users\Wiebe\AppData\Local\Temp\.NETCoreApp,Version=v2.0.AssemblyAttributes.cs(4,99): error CS0246: The type or namespace name 'FrameworkDisplayName' could not be found (are you missing a using directive or an assembly reference?) [C:\Projects\MyCompany\MyCompany.
itrus\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                                                                                                                                                                                              
C:\Users\Wiebe\AppData\Local\Temp\.NETCoreApp,Version=v2.0.AssemblyAttributes.cs(4,122): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(10,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(11,61): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(12,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(13,59): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(14,68): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(15,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(16,53): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   
obj\Debug\netcoreapp2.0\MyCompany.MyProduct.Messages.AssemblyInfo.cs(17,55): error CS0518: Predefined type 'System.String' is not defined or imported [C:\Projects\MyCompany\MyProduct\MyCompany.MyProduct\MyCompany.MyProduct.Messages\MyCompany.MyProduct.Messages.csproj]                   

EDIT: I just had an older version of the SDK in my path. Just wondering why this is not updated automatically when you install newer build tools.

TechnikEmpire commented 7 years ago

@weshaggard so I'm assuming mixing .net standard 2 with 4.6 is unsupported as well? Perhaps tooling could tell us these things so we're not spending hours digging up GitHub tickets trying to figure out why our projects are exploding with ambiguous errors.

weshaggard commented 7 years ago

@weshaggard so I'm assuming mixing .net standard 2 with 4.6 is unsupported as well?

That is correct. See https://docs.microsoft.com/en-us/dotnet/standard/net-standard for the support matrix. I would have expected the tooling to generally block you from adding references to netstandard2.0 libraries from a .NET 4.6 application but there are likely bugs in various scenarios there. If you are hitting upon one please file an issue at https://github.com/dotnet/project-system.

TheCodechimp commented 7 years ago

@weshaggard Are you thinking of .NET core? The entire point of .NET standard is to be an API between the full framework and core. In fact I'm able to use a mix of .NET standard and framework just fine. If something isn't supported it will simply fail and move on.

weshaggard commented 7 years ago

@weshaggard Are you thinking of .NET core?

No. You are exactly correct that .NET Standard is the API between Full and core but each version maps to a particular version of netstandard. So when I say I wouldn't expect that to work it is because .NET 4.6 maps to netstandard1.3 so I would expect the tooling to only allow you to reference up to that netstandard version.

techaimail commented 6 years ago

Adding this reference works for me direct inside csproj file with .NET 4.7.1. <Reference Include="netstandard" />

And for MVC5 projects with .NET 4.7.1 the build process dont copy this file to the output I have to copy manually and that fix the problem. Microsoft please stop your continuous deliver if that is a fuc..k problem deliver, thanks for your advance but not thanks for this fails.

stil commented 6 years ago

@techaimail This method worked for me!

borislavnnikolov commented 6 years ago

@techaimail it worked for me too, thanks.

mattglet commented 6 years ago

Does this solution work for Azure too? When trying to deploy a 4.7 app that references a ns20 package to Azure, I get the following output:

Command: "D:\home\site\deployments\tools\deploy.cmd"
Handling .NET Web Application deployment.
MSBuild auto-detection: using msbuild version '14.0' from 'D:\Program Files (x86)\MSBuild\14.0\bin\amd64'.
All packages listed in packages.config are already installed.
  Core -> D:\home\site\repository\Core\bin\Release\Core.dll
Things\Thing.cs(18,41): error CS0012: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. [D:\home\site\repository\Models\Models.csproj]
Failed exitCode=1, command="D:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe" "D:\home\site\repository\Website\Website.csproj" /nologo /verbosity:m /t:Build /t:pipelinePreDeployCopyAllFilesToOneFolder /p:_PackageTempDir="D:\local\Temp\8d52be78b3540cb";AutoParameterizationWebConfigConnectionStrings=false;Configuration=Release;UseSharedCompilation=false /p:SolutionDir="D:\home\site\repository\.\\"
An error has occurred during web site deployment.
\r\nD:\Program Files (x86)\SiteExtensions\Kudu\67.61109.3117\bin\Scripts\starter.cmd "D:\home\site\deployments\tools\deploy.cmd"
seamus-hoban commented 6 years ago

Hi,

I've got this same/similar problem. I'm running Studio 2017 (15.4.4 ). I created a .NET Core 2.0 command line project, adding Microsoft.AspNetCore and Microsoft.AspNetCore.Mvc, both version 2.0.1 to play around with using the Razor view engine to generate HTML strings rather than views.

It compiles just fine, but when I call IRazorViewEngine.GetView, passing it the name of a cshtml file, I get a compilation exception with the following:

The type 'Attribute' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

and a number of similar complains about System.Void, Boolean etc. I've tried the csproj change listed above without success.

Anyone got any ideas?

Séamus

joperezr commented 6 years ago

I'm running Studio 2017 (15.4.4 ). I created a .NET Core 2.0 command line project

@seamus-hoban Can you try creating a aspnet core app instead? The sdk project type will be different if you create a Command line project than if you create an aspnet core project.

Does this solution work for Azure too? When trying to deploy a 4.7 app that references a ns20 package to Azure, I get the following output:

@mattglet Which version of VS are you using? I ask because if you are running on anything higher than VS15.3 then I would expect your scenario to just work automatically, since in 15.3 we added to the toolset built in support for using netstandard assets on Desktop projects

mattglet commented 6 years ago

@joperezr I'm using VS Community 2017 15.4.2

It seems like the error is on the Azure side of things? The output I pasted is from my Azure Web App's Deployment Details Activity Log.

joperezr commented 6 years ago

I see, that is interesting... so you are saying that if you just F5 in your local machine the Web App runs fine?

mattglet commented 6 years ago

Correct, but I thought Azure supported ns20?

joperezr commented 6 years ago

Yes it should, this might be a different problem. I suspect that perhaps we are not deploying all of the required binaries to Azure, as opposed to the local bin folder where we do deploy the shims. That would explain why running in your local computer works, but running on Azure doesn't.

mattglet commented 6 years ago

That definitely sounds plausible. Which binaries should I look for to confirm if that's the case?

joperezr commented 6 years ago

locally in the bin folder, you should see a netstandard.dll which is just a facade to desktop. If my theory is correct, then you won't have this binary when you are publishing to Azure.

I'm trying to locally put up a repro for this, do you mind giving more details on how are you publishing your app to Azure and also what type of web app it is?

mattglet commented 6 years ago

Yes, I see netstandard.dll in my local bin.

I'm using Azure's built-in deployment features; I've connected the Web App to GitHub and it auto-deploys when it detects any commits to master.

It's a basic MVC ASP.NET Web Application, if that's what you mean by "type" of app.

seamus-hoban commented 6 years ago

@joperezr Thanks for the reply. An aspnet core app works just fine. However, my requirement is to run as a service/scheduled task and generate emails according to the results of polling a database. There is no requirement for pages to be served to users which is why I was hoping to get away with a simple command line program that I could configure to run as required, or a windows service targeting 4.6.2 or above, but if that's how it has to be, fair enough! Thanks again.

joperezr commented 6 years ago

@seamus-hoban I created issue https://github.com/aspnet/Home/issues/2278 on the aspnet repo so that we can fork the discussion of this issue there. It is possible that what you want to do can be accomplished with a console app, so I'll ask you to please go to that issue and add more info to help the aspnet core guys determine whether your scenario should work with a console app or not.

mattglet commented 6 years ago

@joperezr were you able to reproduce?

joperezr commented 6 years ago

@mattglet not yet but we have received several similar reports, so we are looking into it now.

mattglet commented 6 years ago

I added a manual reference to netstandard.dll and added it to the solution - it's a successful temporary workaround until the (what I presume to be an) Azure bug is fixed.

nikitozz commented 6 years ago

@ManfredLange, Just wondering, were you able to find a solution? I'm experiencing the same issue: my build works from VS but not from MSBuild.

Thank you.

joperezr commented 6 years ago

Do you have more than one msbuild installed? it might be that you are using the old one when invoking from command prompt. If so, I would try manually adding a reference to netstandard to your project so that it works with older VS and msbuild.

ManfredLange commented 6 years ago

@nikitozz What we are doing at the moment is this: We parse solution and project file for dependencies, then create our own sequence of building each project. We use batches where multiple things can be build in parallel. We no longer rely on msbuild or dotnet to figure it out for our solution (50+ projects, mix of old/new csproj format, netstandard2.0, netcoreapp2.0, net461).

Then we build all except one project using dotnet build <projectfile> with appropriate parameters e.g. macros required by post-build events. One project is built using msbuild located at C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin this is the latest version included in VS 2017 Professional Version 15.4.4. The "File version" of msbuild.exe as per file properties is 15.4.5.50001.

One additional caveat: we also need to always ensure that we can deploy as Azure App Service. This means it needs to pass a test there as well as we have no influence over what version of msbuild is installed there.

This approach has been working for us for a few weeks now. Ideally we would love to just throw a solution file at either msbuild or dotnet build but so far we ran into problems each time we tried because of the mix of projects in our solution.

Good luck!

shaulbehr commented 6 years ago

I was also getting this error, so I made a reference to NetStandard.Library 2.0.1 using NuGet. Deployed, and still got the same error. Then I saw that netstandard.dll isn't being deployed to the bin folder. And, in fact, NetStandard.dll doesn't show up in the project references in the Solution Explorer. Is that a bug in the NuGet package? Is there some trick I'm missing that is meant to add the DLL reference to the project?

joperezr commented 6 years ago

@shaulbehr what TFM is your project targeting?

shaulbehr commented 6 years ago

@joperezr .NET Framework 4.7.1

joperezr commented 6 years ago

@shaulbehr I see that makes sense, the reason why you aren't seeing it on the bin folder is because netstandard.dll is inbox on 4.7.1. That means that at runtime you won't need to carry it with the app because it will just be loaded from the GAC. What specific error are you seeing? Also, is it at runtime or compile time?

alex-piccione-spin commented 6 years ago

I have a dotnet Core web api project with targetFramwork .Net 4.7. (not 4.7.1)

<Project Sdk="Microsoft.NET.Sdk.Web">
    <PropertyGroup>
        <!--<TargetFramework>netcoreapp2.0</TargetFramework>-->
        <TargetFramework>net47</TargetFramework>
        <RuntimeIdentifier>win7-x64</RuntimeIdentifier>

The solution has some library projects that use .Net Standard 2.0. It is ok.

It was ok. Until I tried to use XmlSeriazer from Syste.Xml.Serialization.

Now I have that error at runtime when I execute this:

var myData = (MyData)new XmlSerializer(typeof(MyData))
                    .Deserialize([something that is an XElement].CreateReader());

The libraries do other some jobs without any error, also this one is fine: var tempString = [something that is an XElement].ToString(); XDocument doc = XDocument.Parse(tempString);

So the problem exists only calling .Deserialize()

Visual Studio Pro 15.5.4 on Windows x64 Everything updated at last version. Assembly netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51

None of the workarounds in this tread worked for me. Any suggestion ?

TechnikEmpire commented 6 years ago

Is anyone here using automatic binding redirects when mixing in .net standard with .net full? If you're not, you should be. And you should be deploying all .config files (where the binding redirects are written to). Once I got automatic binding redirects configured all these gross issues went away.

joperezr commented 6 years ago

@alex-piccione Are you using the latest version of VS? do you have binding redirects turned on as @TechnikEmpire suggests? That combination should make your problem go away.

alex-piccione-spin commented 6 years ago

Yes, I'm using the latest VS (15.5.4). I tried to use:

<PropertyGroup>
  <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
  <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
</PropertyGroup>

and this:

    <PropertyGroup>
        <_HasReferenceToSystemRuntime>true</_HasReferenceToSystemRuntime>
    </PropertyGroup>

(https://github.com/dotnet/standard/issues/552)

I also tried this: <PackageReference Include="NETStandard.Library" Version="2.0.1" /> that is exactly the same package referenced by the Library projects (.Net Standard)

and this: <Reference Include="netstandard" />

I tried also to reference the NETStandard.Library.NETFramework v2.0.0-preview2-....

I cannot switch from
Project Sdk="Microsoft.NET.Sdk.Web" to Project Sdk="Microsoft.NET.Sdk" because it is a web project.

To be honest I haven't understood what "binding" means here...
and the error is raised at runtime when I debug the code (not after the deploy).

I tried to pass the XmlSerializer directly to the class in the .Net Standard library, the result is strange. It does not raise an error but it return a null object. (The classes that map the XML is generated by xsd.exe).

The XmlSerializer instantiated in the library raise the error not in the .Deserialize() call as I say before but when I try to create it ( new XmlSerializer(typeof(MyData)) ).

Give up. Using XDocument and XLinq works without any problems so I'm parsing the XML myself and I deleted all the code for this experiments. I cannot test it anymore.

That's all.

Leon99 commented 6 years ago

ASP.NET app targeting 4.7.1, solution is a mix of .NET FX and .NET Standard projects, including .NET Standard projects referencing .NET FX libraries. VS 15.5.6 with .NET Core SDK 2.1.4 installed. The only advice from this thread that helped to avoid

The type 'Decimal' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

in an .cshtml was adding `

True
</Reference>`

to the web app project. MSBuild works too.

mallochine commented 6 years ago

Since NETStandard.Library.NETFramework, and we should install the .NET Core 2.0 SDK, how do we do this from nuget CLI?