.NET Core MSTest project can't find VisualStudio type or namespace in Microsoft namespace - visual-studio

Microsoft Visual Studio Professional 2019
Version 16.0.0
VisualStudio.16.Release/16.0.0+28729.10
I added a .NET Core 2.2 MSTest project and it added dependencies :
Microsoft.NET.Test.Sdk v16.0.1 ( I updated to v16.2.0 )
Microsoft.NET.Test.Sdk v1.3.2 ( I updated to v1.4.0 )
MSTest.TestFramework v1.3.2 ( I updated to v1.4.0 )
I compile and get this error :
CS0234 The type or namespace name 'VisualStudio' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?) ...\packages\microsoft.net.test.sdk\16.2.0\build\netcoreapp1.0\Microsoft.NET.Test.Sdk.Program.cs
Microsoft.NET.Test.Sdk.Program.cs
// <auto-generated> This file has been auto generated. </auto-generated>
using System;
[Microsoft.VisualStudio.TestPlatform.TestSDKAutoGeneratedCode]
class AutoGeneratedProgram {static void Main(string[] args){}}
Couple of observations :
Project is .NET Core 2.2 but it's using package from
netcoreapp1.0 folder
NuGet package manager successfully added package Microsoft.NET.Test.Sdk v16.0.1 but on build it has an unresolved
reference

The type or namespace name 'VisualStudio' does not exist in the
namespace 'Microsoft' (are you missing an assembly reference?)
...\packages\microsoft.net.test.sdk\16.2.0\build\netcoreapp1.0\Microsoft.NET.Test.Sdk.Program.cs
If we consume the Microsoft.NET.Test.Sdk package, when we compile and build our project, the Microsoft.NET.Test.Sdk.Program.cs will also be compiled by the csc.exe during the build.
So the error message indicates the Microsoft.VisualStudio.TestPlatform.TestSDKAutoGeneratedCode attribute can't be recognized well because something is wrong with the reference to Microsoft.TestPlatform.ObjectModel.dll.
Note:
1.Microsoft.VisualStudio.TestPlatform.TestSDKAutoGeneratedCode comes from assembly Microsoft.TestPlatform.ObjectModel.dll.
2.Microsoft.NET.Test.Sdk package depends on Microsoft.TestPlatform.TestHost package, and Microsoft.TestPlatform.TestHost package depends on Microsoft.TestPlatform.ObjectModel package.
If those packages are installed successfully, the compile and build should work. So actually I think something is wrong in your installed packages.
Some simple suggestions you can try:
1.Go Tools=>Nuget Package Manager=>Package Manager settings to make sure two options of Package Restore are enabled. And then delete the bin, obj folders and run a rebuild.
2.If #1 not works, try clean the nuget cache by UI in VS IDE, and then again delete the bin, obj folders, then run a rebuild.
3.Please update your VS IDE to latest version, 16.0.0 is too old, and latest version has fixed some issues.
Project is .NET Core 2.2 but it's using package from netcoreapp1.0
folder
If you open the package in path ...\packages\microsoft.net.test.sdk\16.2.0\build you can find this package only have three version of assemblies, net40, netcoreapp1.0 and uap10.0. Since your project is .net core 2.2, it will reference the assembly in netcoreapp1.0 folder. It's expected behavior.

Related

Error when adding new Nuget to a .Net Standard Project

I am working on referencing another set of .dlls in another project and have bundled it up via Nuget:
I get this error:
Severity Code Description Project File Line Suppression State
Error NU1701 Package 'MyPackageImTryingToInstall' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v2.1'. This package may not be fully compatible with your project. 1
I understand the error, but how do I make .Nuget restore with .Net standard?
Just found that if I reference the Nuget in a .Net Framework 4.6.1 project - it works fine.
It has something to do with making a nuget from .net standard to .net standard.
I had to add lib folders for the target frameworks I wanted to add the nuget package to:
For the files section in the nuspec I needed to make a \netstandard2.0 folder and \461 folder

Xamarin.Android: Package XX is not compatible with monoandroid81 (MonoAndroid,Version=v8.1)

I encounter a stranger behavior with a Xamarin.Android project in Visual Studio on Windows.
I've created a new Android blank project, and I try ton install the NuGet package "AForge" (a mathematics library), but I get the following error message:
Package AForge 2.2.5 is not compatible with monoandroid81
(MonoAndroid,Version=v8.1).
I've already tried to re create several projects, after having relaunched Visual Studio and the computer, but the problem is still the same.
However, if I do the same thing on Mac, through Visual Studio for Mac, I don't encounter the same problem: the package is well installed.
In add, I can see in the package.config file, that the package il well related to monodroid81:
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="AForge" version="2.2.5" targetFramework="monoandroid81" />
</packages>
Would you have any explanation about this issue?
Update: new issue
Hi #Leo Liu-MSFT, I come back to you as I encounter an new issue. The dll copy works fine locally, but I get an error on AppCenter:
CoreCompile:
/Library/Frameworks/Mono.framework/Versions/5.10.1/lib/mono/4.5/csc.exe
/noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4
/define:DEBUG;TRACE;XAMARIN_ANDROID_v1_0;MOBILE;ANDROID;ANDROID_1;ANDROID_2;ANDROID_3;ANDROID_4;ANDROID_5;ANDROID_6;ANDROID_7;ANDROID_8;ANDROID_9;ANDROID_10;ANDROID_11;ANDROID_12;ANDROID_13;ANDROID_14;ANDROID_15;ANDROID_16;ANDROID_17;ANDROID_18;ANDROID_19;ANDROID_20;ANDROID_21;ANDROID_22;ANDROID_23;ANDROID_24;ANDROID_25;ANDROID_26;ANDROID_27
/reference:/Library/Frameworks/Mono.framework/External/xbuild-frameworks/MonoAndroid/v1.0/Java.Interop.dll
/reference:/Users/vsts/.nuget/packages/microsoft.appcenter.analytics/1.7.0/lib/MonoAndroid403/Microsoft.AppCenter.Analytics.Android.Bindings.dll
/reference:/Users/vsts/.nuget/packages/microsoft.appcenter.analytics/1.7.0/lib/MonoAndroid403/Microsoft.AppCenter.Analytics.dll
/reference:/Users/vsts/.nuget/packages/...
Services/AudioService.cs(8,7): error CS0246: The type or namespace
name 'AForge' could not be found (are you missing a using directive or
an assembly reference?)
[/Users/vsts/agent/2.136.1/work/1/s/XxxApp/XxxApp.csproj] Done
Building Project
"/Users/vsts/agent/2.136.1/work/1/s/XxxApp/XxxApp.csproj"
(PackageForAndroid target(s)) -- FAILED.
So I tried your suggestion, but I get an error when I try to save the package:
a local file header is corrupted'
Would you have another suggestion?
Would you have any explanation about this issue?
You can get the official document here:
Description: With PackageReference, assemblies present at the root of
lib folder without a target framework specific sub-folder are ignored.
NuGet looks for a sub-folder matching the target framework moniker
(TFM) corresponding to the project’s target framework and installs the
matching assemblies into the project.
In this case, NuGet will consider installing this package to the .NET Framework, which is not compatible with monoandroid81. Then you will that error "Package AForge 2.2.5 is not compatible with monoandroid81".
To resolve this issue, the best way is contact the author of the AForge NuGet package to update this package, or you can also add reference dll file directly to your project.
Besides, if you still want to use nuget to manager this package, I would like provide you a workaround to resolve this issue:
Download this nuget package from nuget.org.
Copy the download package, rename it with .zip, like aforge.2.2.5 - Copy.nupkg.zip, then unzip it.
Open the package aforge.2.2.5.nupkg with NuGet Package Explorer(Get it from Microsoft store), add a new folder MonoAndroid81 under the lib node, add exists file AForge.dll and AForge.xml from the copy folder aforge.2.2.5 - Copy.nupkg.zip, save this nuget package.
Add this new create nuget package to the nuget local feed, then add this nuget package to the project. Do not forget delete the nuget package cache in the C:\Users\<UserName>\.nuget\packages\aforge before you add the package.
Hope this helps.

The type or namespace name does not exist in the namespace. .NETCore - Visual Studio 2017

I am using a mac with visual studio 2017. I'm trying to start up a project with NuGet packages inside. When I right click on the source and go to update NuGet packages, I receive incompatible errors for 15 of the packages.
Checking compatibility for System.Net.WebSockets 4.0.0 with
.NETCoreApp,Version=v1.1. Incompatible packages: 15 Package restore
failed. Rolling back package changes for 'project.api'.
When I restore packages for the solution, it works successfully. When I go to build the project I get 28 errors. All with the same text -
error CS0234: The type or namespace name '' does not exist in the
namespace 'project.api' (are you missing an assembly reference?)
This issue does not persist on a counterparts Windows machine. I have no idea what to do or where to go.
Side note - unsure where to go to the NuGet package manager then go to package manager settings. This exists on windows but not Mac it seems.
The latest version was not pushed to the repo. This was why I was getting the errors. So the build error is fixed but the update NuGet packages are still incompatible. Not going to worry about that for now.

NuGet packages issue when building on TeamCity

I have some solution created in Visual Studio 2015, with usages of NuGet packages.
When I compile the solution from Visual Studio (both of settings "Allow to download missing packages"
and "Automatically check for missing packages during build" are set ON) - it works.
But when compiling the solution on TeamCity (which calls MSBuild for build) - it fails:
Error : the type or namespace name 'someName' cannot be found (are you missing using directive or assembly reference?), where 'someName' defined in the assembly to be installed by NuGet
In TeamCity there are two separate steps defined:
NuGet install - it was verified that packages installed on build agent
Build itself
Is there a parameter of MSBuild to be checked?
What can be the cause of the issue?
Error : the type or namespace name 'someName' cannot be found (are you missing using directive or assembly reference?) , where 'someName' defined in the assembly to be installed by Nuget
According to the error log, you need add a step to your build process to restore all NuGet packages. You can refer to the document NuGet Package Restore with TeamCity for more detail.

Getting the error "Error CS0234: The type or namespace name `CrossCore' does not exist in the namespace `Cirrious'

Getting the error "Error CS0234: The type or namespace name CrossCore' does not exist in the namespaceCirrious'. Are you missing an assembly reference?" for PCL. And unable to update packages.
We are getting error when we are trying to update packages in Xamarin studio PCL in Mac machine. “Could not install package 'MvvmCross.PortableSupport 3.2.2'. You are trying to install this package into a project that targets 'portable-Profile78', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.”
If you are updating an old MvvmCross project then that is probably why. Starting with 3.2.1 MvvmCross moved to PCL profile 259. You'll need to change the profile of your pcl core to this profile or something else that is compatible.
After uninstall xamarin by following steps in the url http://developer.xamarin.com/guides/cross-platform/getting_started/installation/uninstalling_xamarin/
and reinstall the Xamarin Studio, the Nuget packages are started updating.

Resources