I have a useful extension for Xunit which I use through various .NET 3.1 projects. I want to build a NuGet package to easily distribute it.
But when I add a Xunit dependency to my Visual Studio project it is immediately marked as Unit Test project and stops generating .nupkg file (I have "Generate NuGet package on build" checked in the project settings).
Can anyone help me?
I ended up deleting unnecessary dependencies like "Microsoft.NET.Test.Sdk" after that my project stopped being a unit test project. Then I switched Xunit dependency to xunit.extensibility.core which is supposed to be used especially for extensions.
Finally, Visual Studion successfully generated .nupkg file on build
Related
I have a solution file which contains two project, one is main project and the other is an unit test project.
I had them install both NuGet Package NUnit and NUNit3TestAdapter
However, I still cannot create nunit unit test near the function I want to test by the mouse right click event
As you can see, only MSTestV2 framework is detected.
My question is: How can I use the NUnit framework to create unit tests in Visual Studio 2022 Community?
The TestGenerator extension has not been released for x64 which VS2022 yet.
What you do is to use command line tools:
Create a new folder for your test projects.
The run :
dotnet new nunit
This will create a new NUnit test project.
Add this project to your solution and add a project reference from there test project to your other project "to be tested", and off you go :-)
I'm trying to deploy a netstandard2.0 class library nuget to a local folder repository (specified in FolderProfile.pubxml). This works fine via VisualStudio's publish context action on a project: the process behind the scenes builds the project and packs desired items according to project.csproj and then copies the nuget package according to FolderProfile.pubxml. I've expected this could be achieved with msbuild as well (to be used in scripts).
msbuild /t:Publish /p:PublishProfile=FolderProfile.pubxml
This builds the project and copies content of bin/Debug/netstandard2.0 to the local folder repository. Unfortunately this differs from what was requested, the PublishProfile specifies Release configuration and project.csproj explicitly states just .dll to be packed (neither .deps.json nor .pdb)
msbuild /t:Pack
Packs the nuget content according to the project.csproj but it leaves the package in bin/Debug.
Switch to Release could be achieved via /p:Configuration=Release but that is still not enough to achieve the desired.
I've created simple a demonstration project, available at https://github.com/JanCervak/NugetPublishDifferenceRepro,
local folder repository is set to %TEMP%
Used VS 2019 16.8.3
The publish button of VS IDE for class library projects is msbuild -t:pack rather than msbuild -t:publish.
On VS IDE, when you click on the Publish button for lib projects, it actually does Pack button to create the nuget packages which reads from the pubxml file. It is the special feature of VS IDE and caused by the integrated tasks, tools from VS IDE. In other words, it is designed by that.
For different vs projects, Publish Button does different functions.
However, when you use msbuild -t:publish for lib projects from command line, which gets rid of the VS IDE environment, it does the function like the web projects, windows projects.(put the final output files into the custom publish folder).
So if you want to use commands which does the same function as VS IDE for lib projects, you should abandon the pubxml file and use this command:
msbuild NugetPublishDifferenceRepro.csproj -t:pack -p:Configuration=Release;Platform=AnyCPU;PackageOutputPath=%Temp%
PackageOutputPath is for pack target and specify the path of the generated nuget package.
I want to install a nuget package (ReportGenerator) to help collate coverage reports across various projects in a solution in Azure. Some of these projects are SQL projects with unit tests undertaken with TsqlT. However I need to add a refernce to ReportGenerator in the test sqlProj projects.
Nuget package manager doesnt seem supported;
is there anyway I can add this package as a reference?
We have a solution which contains several projects. Some projects have NuGet packages installed, for example Json.NET. The whole solution is checked in to TFS Version Control, without the packages folder. We have set up Automatic Package Restore according to the "Nuget 2.7+ method" as described in the Nuget documentation (actually we didn't set up that much since all this is enabled by default).
When we build this solution on another computer, all packages are getting restored.
When we build this solution on our TFS 2013 Build server, all packages are also getting restored.
Now here comes the problem:
When we create a build on our TFS 2013 Build Server which should build only one of the projects in the solution (so targeting the .csproj file instead of the .sln file) the nuget packages are NOT getting restored!
Can anyone tell me why this is happening, or tell me if this is by design? I really don't want to build the whole solution, since it is a release build for only a single small project, but i do want the packages getting restored automaticly...
I believe the Automatic Package Restore hooks into the Build Solution event. Since there's no solution, it's not triggering the restore.
To build a single project, you may need to create a new solution that references just that project.
I can see both test projects from the NUnit Gui (loaded separately) but I can not see both projects from the Visual Studio Test View. The Test View only shows the first/original project. Hitting reload doesn't do anything. How do I get the Test View to display the second/later project? It should show both at the same time/same view, yes?
If I can only see one project's test in the Test View by design, how do I get the Test View to change projects?
Details:
I created the second project by hand ie not "create a test" as a project library with the nunit.framework.dll referenced. I checked the assembly files of the two projects as well as the properties and they look the same.
I'm on VS 2010 Professional using NUnit 2.6.0.12051 with "Visual NUnit 2010" version 1.2.4 extension installed.
I have one NUnit test project that is working both in VS Test View and NUnit Gui. I added a second project with a [TestFixture] class and a [Test] method. All projects build sucessfully. Both tests refer to the nunit.framework.dll in a parent directory to both.
There is a tag in the project file describing a project as a test project.
In the PropertyGroup section of the csprj file, add this:
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
See more details here:
http://www.kindblad.com/2010/08/07/how-to-change-an-existing-visual-studio-project-into-a-test-project
There are many problems that can cause this. Here's what mine was:
I had 2 NUnit test projects.
"Test Explorer" -> "Run All" would only find tests from one project.
Explicitly right clicking on one of the tests that wasn't found and clicking "Run Test" resulted in "No tests found." in the Output window.
All projects on all configurations were set to Any CPU, but it didn't matter if X86 was chosen for everything either.
The problem was that my Visual Studio (2015, FWIW) was using Test Adapter 2.x, and one of my projects had pulled NUnit 3.0 using NuGet. Test Adapter 2.x doesn't run NUnit 3 tests, so my NUnit 3 test project was being ignored.
To solve the problem:
Uninstall all NUnit Test Adapters (from Visual Studio -> Tools -> Extensions and Updates and from each project's NuGet Package Manager window).
Update all test projects to NUnit 3.0 using each project's NuGet Package Manager Window.
Install the NUnit3 Test Adapter from Visual Studio -> Tools -> Extensions and Updates
Notes:
If you need to stick to NUnit 2, then just install the appropriate Test Adapter. The important thing is consistency.
If you were using test adapters installed by NuGet before, but switched to a Visual Studio Extension, then you may have problems loading resources/files from path strings. See this answer to solve that issue.