I want to add a reference to an assembly in my unit test project, because it has to be referenced in order to call the method to be tested, but... I can't. I don't have the option to do so in the "Add reference" window in Visual Studio. I can only add Project references or Browse for dll references (see image below, left is unit test project and right is the app project's "Add reference" window)
I have the error "The type is defined in an assembly that is not referenced. You must add a reference to the assembly.", but when I go ahead and use the quick action to do so, nothing happens.
Why can't I add a reference to the assembly and is there another way around the missing assembly issue?
Note: Using Visual Studio 2017
Following the discussion with #Dai, the assembly references weren't available because an NUnit Test Project created in Visual Studio is created using .NET Core rather than .NET Framework.
To have access to .NET Framework assemblies, you need to create a .NET Framework Unit Test Project and then replace the MS Test Framework with the NUnit Test Framework.
Related
I am working inside Visual Studio 2017, I have 2 DAC's and 1 graph file all in App_Runtimecode, is there a build or other setting that I that I have to set so that the Graph can "find" the DAC's for the autocomplete?
Thanks
Files in App_RuntimeCode are compiled dynamically on demand by IIS. IntelliSense works on statically compiled code and therefore can't parse dynamic code. To have complete IntelliSense support requires creating an Extension Library instead of a Runtime customization project.
I'm looking for some help to setup my Visual Studio for Mac project properly. I'm new to Visual Studio Mac and would appreciate a shove down the right road.
I have a large class library, originally developed in visual studio 2017 on Windows.I'd like to use much of that code to develop an iOS application. This class library requires references to:
System
System.Runtime.Serialization
System.ServiceModel
System.ServiceModel.Web
System.Web.
I have tried porting that code to a Portable Class Library in Visual Studio for Mac. However PCLs don't allow you to reference the above assemblies (unless I'm missing something).
So I then ported it to .NET Library project (Other -> .NET -> Library) project. However, my iOS app won't allow references to that project type because VS for Mac says it has an "Incompatible Target Framework: .NETFramework, Version-v4.6.1).
What project type should I be using for this class library so that it can reference the needed .NET assemblies and it can be referenced from my iOS application?
Possible options:
Use a different Portable Class Library (PCL) profile.
Use a .NET Standard project.
Use a shared project.
For everything apart from System.Web, there are PCL profiles that have the assemblies you are looking for. You can see which assemblies are available on the Mac by looking in the PCL directory:
/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/xbuild-frameworks/.NETPortable
If you open a terminal window there you can run a search, find . -name "System.ServiceModel.Web.dll", or browse the folders using Finder to find a PCL profile that has the assemblies you need.
Another possibility would be to use a .NET Standard 2.0 project which has a lot of assemblies that can be used and supports being referenced by a Xamarin.iOS project. You may need to install some other System.* NuGet packages to provide the required assemblies.
The namespaces available in .NET Standard 2.0 are documented:
https://learn.microsoft.com/en-us/dotnet/api/?view=netstandard-2.0
Another option is using a shared project. This does not have assembly references itself but is basically shared code that is compiled into all projects that reference it. Here you can use #ifdefs for any code that is iOS or Android specific.
Background: learning about MVC, Bootstrap, etc. So, new to doing this in Visual Studio. More of a C# backend programmer / hand-rolled html/css/js fiddler.
I'm trying to add a unit test to an MVC project, and I get the uselessly generic "A reference to 'Your Project Name' could not be added." error when I try to reference my main project so I can test against my Model classes.
Visual Studio 2015 Professional
Created new Project with File -> New Project -> Templates -> Visual C# -> Web -> ASP.NET Web Application
Selected "Web Application" from ASP.NET 5 Preview Templates
Added some code, including a class to serve as a model for Code First.
Added a Unit Test project under the Solution folder by right-clicking and choosing Add -> New Project, under the Visual C# folder for the templates I picked Test -> Unit Test Project. The targeted framework at the top was set to .NET Framework 4.5.2
Googling around suggested that I had a target framework mismatch. I don't know how to check the target framework on a MVC project I guess, the Project Properties window lists Application and Solution DNX SDK version ( set to 1.0.0-beta5, platform .NET Framework ) but doesn't tell me what framework I'm targeting.
How I can utilize Microsoft's unit testing framework with this kind of project?
In Visual Studio, open the Package Manager Console (TOOLS > Nuget Package Manager > Package Manager Console) and type the following command:
Update-Package
This will update and 'level' all packages of both projects and any version mismatch should be fixed.
In a website project, when I press add reference. All build in assemblies in .net are showing twice, and when adding one it also adds the other and fails the add.
When I right click on a project in my solution and go into the properties, I don't see the Compile tab on the left. I see Application, Build, Build Events and then the next one is Debug.
I've Googled for this but couldn't find anything, and also couldn't find anything here. Does anyone have any idea what I'm doing wrong?
Many thanks!
The Compile tab shows up for Visual Basic projects, but not for C# projects. For Visual Basic it mainly houses constructs specific to VB, like OPTION EXPLICIT, but there are elements like target platform that are found on the Build tab for C#. The target framework, available under the Advanced Compile Options of the Visual Basic Compile tab is found on the C# Application tab.
UPDATE: With Update 2 of Visual Studio 2012 I'm now seeing Target Framework for a VB project also in the Application tab.