I'm using one of those new "Class Library (NuGet Package)" templates from Visual Studio, and I want to create an xUnit test library for it.
The problem is, when I create a new .csproj library and try to reference the .xproj package, Visual Studio says "The reference to XXXX could not be resolved."
Why is this happening and what can I do to fix this?
You can use the SideWaffle template pack VS extension to create xUnit project templates using the new xproj project type. It is developed by a Microsoft developer and is the recommended approach at the moment (It is what they use in ASP.NET 5).
Related
I'm converting some existing C# projects to be defined in CMake -- moving from the previous include_external_msproject() directive to the newer full support for C#.
But I'm not seeing how to convert projects of the Visual C# Unit Test Project type. I'm able to build them as libraries, and compile them successfully -- but Visual Studio doesn't show them as unit test projects, just as regular libraries. Most crucially, the tests aren't visible to the Test Explorer.
Things I've already tried include:
Adding TestProjectType=UnitTest as a target property:
<TestProjectType>UnitTest</TestProjectType>
Adding a reference path, as follows, as a target property:
<ReferencePath>$(ProgramFiles)/Common Files/microsoft shared/VSTT/$(VisualStudioVersion)/UITestExtensionPackages</ReferencePath>
Adding Microsoft.VisualStudio.QualityTools.UnitTestFramework as a project reference (using CMake's VS_DOTNET_REFERENCES property).
I'm using Microsoft Visual Studio Professional 2015, CMake 3.13.2, .NET Framework 4.5.2 (but I suspect the issue isn't specific to my particular version combination).
Manually adding <TestProjectType>UnitTest</TestProjectType>, made my unit test project show up as unit test. Trying to figure out how to do that using cmake.
Update: the following shows the project as unittest
set_target_properties(${target_name}
PROPERTIES
VS_GLOBAL_PROJECT_TYPES "{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
)
Documentation for VS_GLOBAL_PROJECT_TYPES is here.
I found this documentation for Project Guid: Visual Studio project type guids
Thanks #bhardwajs, your answer helped me.
You can also add TestProjectType to global properties:
set_target_properties(${target_name} PROPERTIES
VS_GLOBAL_TestProjectType "UnitTest"
VS_GLOBAL_PROJECT_TYPES "{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}")
I have one PCL project, in this project I made Xunit project, which I want to reference my PCL project to test it.
When I'm trying to add a reference, I cant check it, because of I have an error like this:
Incompatible target framework: .NETPortable,Version=v.4.5,profile=Profile111)
I'm using Visual studio Mac, I've also updated everything from Check Updates
Also updated all Nuget packages.
I am assuming this is a .NET Core xUnit project which is trying to reference the PCL project.
Currently this is prevented in Visual Studio for Mac 7.2 and earlier versions. In Visual Studio for Mac 7.3 and later, currently available on the alpha channel, it is possible to reference a PCL project from a .NET Core project.
For Visual Studio for Mac 7.2 the only workaround would be to add the project reference manually by editing the .csproj in the text editor. For example:
<ItemGroup>
<ProjectReference Include="..\PclProject\PclProject.csproj" />
</ItemGroup>
I'm having a problem when creating a project in Visual Studio 2015 Community Edition.
I am trying to create a .NET 4.5.2 project for parsing XML documents.
After creating the project the structure looks like this
Which I believe is a vNext structure. New json style.
The real problem arises when I add a reference to XDocument via NuGet
I tried poking around posts with similar issues but couldn't find one the wasn't trying to use/mix .NET 5.
I have tried doing a repair of my installation.
The class library template in the Web section is for the new .NET Core libraries. You will find the library template you are looking for under the Windows section.
I have an add in which is used to add dll to the project based on the framework of the project.for this i need to know the .NET Frame work of the project and i can achieve this by reading the .csproj file of the project. But what I am looking is Ways to get it via dte/vsproject object. is there any way?
Thanks,
You can get it from EnvDTE, using:
Project.Properties.Item("TargetFramework").Value
See:
HOWTO: Get the target .NET Framework of a Visual Studio 2008 project from a Visual Studio add-in or macro
I'm trying to figure out what an "ASP.NET 5 Class Library" (vNext) C# project has to do with ASP.NET. Why create a project with this template rather than just a regular C# "Class Library" project?
I like the new features, such as project.json file rather than .csproj file etc, but it doesn't seem right to create an "ASP.NET" class library when the project has nothing to do with ASP.NET or IIS etc. It's just a project for the business logic layer. A new WebApi ASP.NET web site will eventually reference this project, but that's not relevant at this point.
Is it just badly named? Should it just be called "vNext Class Library" and not use an icon that looks like a web app?
Why create an ASP.NET 5 Class Library project?
There are a number of benefits of ASP.NET 5 Class Library projects (.kproj) over Class Library projects (.csproj):
ASP.NET 5 class libraries easily support cross-compiling projects to multiple targets, such as aspnet50, aspnetcore50, net45, and various other portable class library variations. This includes rich Visual Studio support for Intellisense to notify you which APIs are available for which targets.
NuGet packages are automatically created, which is an extremely common thing to do with class libraries.
Better productivity when it comes to things like automatically refreshing Solution Explorer when the file system changes. Fewer conflicts in source control when trying to merge conflicting changes in the *.csproj file.
Can be compiled cross-platform (in part because it doesn't depend on MSBuild)
You can reference a *.csproj project from a *.kproj project (this was just made a lot easier with the new preview of Visual Studio 2015), but it was always possible with some manual steps.
Why does the name have "ASP.NET" in it?
As far as the names goes, it's a relic of history that will soon be addressed. The new project type is useful far beyond ASP.NET 5 applications. Expect to see new names in a future preview of Visual Studio:
.NET Console Application (Cross-platform)
.NET Class Library (Cross-platform)
Update 5/13/2015
With the release of Visual Studio 2015 RC you can see the updated project template names:
Class Library (Package)
Console Application (Package)
These use the project.json file and the .NET Execution Environment (DNX) to build, run, and package (into a NuGet package) the project.
These project templates continue to show up in the New Project dialog under the "Web" node, but now also show up in the main "Visual C#" node as well.
This is an interesting observation, the current template will generate a class library compatible with ASP.NET 5 runtime. You don't get that from the normal C# class library.
I filed the following issue for tracking this design question - https://github.com/aspnet/Home/issues/281
From what I understand one benefit is that the end product of ASP.NET 5 Class Library project is a NuGet package (rather than just the .dll assembly).
You can generate the NuGet package by right clicking the project in Visual Studio 2015 and choosing the "Publish..." option. Or you can use "KPM pack" at the command line.
Also, you have the ability to use the ASP.NET 5 Core runtime so that your library can run cross-platform .