I am trying to run NUnit tests for a .NET Core 2.0 project in Visual Studio 2017 through ReSharper. I've had the test .proj assembly set both as console application and class library. So it doesn't seem to be the output type. The solution does not discover any unit test and just displays no results with 0 tests run.
Here is my .csproj file for the tests project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>eCorp.WebStore.OrderService.Tests</AssemblyName>
<RootNamespace>eCorp.WebStore.OrderService.Tests</RootNamespace>
<ApplicationIcon />
<OutputType>Exe</OutputType>
<StartupObject />
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.5.0" />
<PackageReference Include="NUnit" Version="3.9.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.9.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Core\OrderService.Domain\OrderService.Domain.csproj" />
<ProjectReference Include="..\..\Core\OrderService.Infrastructure\OrderService.Infrastructure.csproj" />
</ItemGroup>
</Project>
I found this already:
Run NUnit tests in .NET Core
None of the provided solutions seem to work for me.
I solved by installing the following NuGet packages
NUnit
NUnit3TestAdapter
Microsoft.NET.Test.Sdk
ReSharper is known to have problems running .NET Core 2.0 tests in Visual Studio 2017. Try to run them without ReSharper.
For more information see this Stack Overflow question and answers: .NET Core 2.0 and xUnit doesn't run.
If you've installed the packages in D.G's answer and it still doesn't work, check if you need to update ReSharper. That worked for me.
Related
I'm trying to use Xplot.Plotly in an f# project using
Visual Studio for Mac. When I debug I obtain
"Could not load file or assembly
'FSharp.Core, Version=4.7.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
If If I do dotnet run I obtain:
Unhandled exception.
Cannot print exception string because Exception.ToString() failed.
the project file references are as follows
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="MathNet.Numerics.FSharp" Version="4.9.1" />
<PackageReference Include="XPlot.Plotly" Version="3.0.1" />
<PackageReference Include="FSharp.Core" Version="4.7.1" />
</ItemGroup>
</Project>
and the project view screen shot as follows:
I'm not clear why VS shows 4.5.2 instead of 4.7.0.0?
I've also tried moving explicityly the Fsharp.core.dll version 4.7.0.0 to the bin directory. From the console the result is the same. If I run via Visual studio Fsharp.core.dll version 4.7.0.0 gets overwritten with 4.5.2.0 and fails in the same way as above.
Update: Workaround is simply do Clean from Visual Studio. and then run dotnet build from the console. Then you can debug from Visual Studio if needed.
Currently, VS for Mac requires Mono, which is locked to F# 4.5 and has numerous other troubles loading .NET Standard 2.0 components. Eventually, VS for Mac will be updated and it will support loading higher versions of the F# compiler and FSharp.Core.
I'm hoping someone has some advice on the best way to use Teamcity to build and publish a solution that has both .NET Core/standard 2.0 projects and .NET framework 4.6.x projects in it.
Currently, I can build the project, run tests, but I can't figure out a way to publish it via the dotnet-cli. We have a relatively large solution, approximately 75 projects in .NET core/standard and 5 or some framework projects. Running dotnet publish on our solution results in the following error on the .NET framework projects:
error: C:\Program Files\dotnet\sdk\2.0.3\Microsoft.Common.CurrentVersion.targets(3861,5): error MSB4062: The "Microsoft.Build.Tasks.ResolveManifestFiles" task could not be loaded from the assembly Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask.
It would be ideal if the cli could attempt to ignore publishing the .NET Framework projects, but it doesn't seem to be possible. I'm thinking about writing a powershell script to check all csproj files in our solution for an appropriate TargetFramework value (i.e netstandard2.0/netcoreapp2.0), and publish them individually, but maybe someone knows a better way?
If anyone is facing the same issue, you need to restructure your csproj file as suggested by #nvoigt.
You can follow the steps as described in the post Old csproj to new csproj
You can start clearing out your csproj file and start with below format.
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net462</TargetFramework> // if your target is 4.6.2
</PropertyGroup>
</Project>
And now you can add remaining of your dependency like below.
...
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.4" />
<PackageReference Include="Microsoft.Azure.Storage.Blob" Version="11.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="3.0.0" />
<PackageReference Include="Microsoft.Azure.KeyVault" Version="2.0.6" />
<PackageReference Include="NLog" Version="4.7.5" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.6.5" />
</ItemGroup>
...
you can find more details on the post.
I have following project
/proj.sln
/some.lib.test/
/some.lib.test.csproj
where
some.lib.test.csproj
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
<PackageReference Include="xunit" Version="2.3.0-beta5-build3769" />
<DotNetCliToolReference Include="dotnet-xunit" Version="2.3.0-beta5-build3769" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
</ItemGroup>
</Project>
How to setup Team Services build to get tests normally viewed?
I try to search web but don't get valid result.
dotnet test - works, but not create VSTS report
dotnet xunit - don't work at all (cannot be used at sln level i think)
VSTS Test Task - don't sees any results
In logs:
In logs:
c:\bin\vs\Common7\IDE\CommonExtensions\Microsoft\TestWindow\vstest.console.exe
C:\agent_work\1\s\iskkonekb.kuvera.model.test\bin\release\netcoreapp2.0\iskkonekb.kuvera.model.test.dll /EnableCodeCoverage /logger:trx "/TestAdapterPath:"C:\agent_work\1\s\packages"" /InIsolation /UseVsixExtensions:true /Framework:FrameworkCore10
[xUnit.net 00:00:00.1787131] Skipping: iskkonekb.kuvera.model.test (Could not find any of the following assemblies: xunit.execution.desktop.dll)
I cannot find xunit.execution.desktop in NUgets
So it sees XUNit but cannot xall
Added - not helped
You can use .NET Core Test task with --logger arguments to generate the test result file, then publish test result through Publish Test Results task:
Delete files task (Source Folder: $(System.DefaultWorkingDirectory); Contents: **/TestResults/**)
.NET Core Restore
.NET Core Build
.NET Core Test (Arguments: --configuration $(BuildConfiguration) --logger "trx")
Publish Test Results (Test result format:VSTest; Test results files:**\*.trx; Search folder: $(System.DefaultWorkingDirectory))
After moving project from .Net Core 1.1 to .Net Core 2 I just noticed that my xUnit tests are not discovered in VS 2017 anymore...
any ideas how to get them back? :)
UPDATE
After some deeper research I found out that my problem related to this error in my test project: "Could not load file or assembly 'System.Runtime, Version=4.1.1.0"
more details here:
https://developercommunity.visualstudio.com/content/problem/95070/could-not-load-file-or-assembly-systemruntime-vers.html
I ran into the exact same issue and after banging my head for a couple of hours I discovered that xunit in .Net Core 2 requires your Target Framework must be netcoreapp2.0 and not netstandard2.0.
Sample working CS Proj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.3.0" />
<PackageReference Include="xunit" Version="2.2.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.2.0" />
</ItemGroup>
</Project>
How to patch Asp.Net Core project (csproj) in order to build versioned binaries with AppVeyor?
Is there a way to apply versioning separately for AssemblyVersion and FileVersion?
AppVeyor has predefined step to patch AssemblyInfo.cs file, but it isn't included into project and functionality of AssemblyInfo moved to csproj file, therefore it's not clear how to deal with versioning.
Appreciate you help!
As .NET Core .csproj is a regular XML you can use PowerShell script to update the version information in it. For example, you might have the following MyProject\MyProject.csproj:
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
<Version>1.2.3.4</Version>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
</ItemGroup>
</Project>
Then on AppVeyor the script patching <Version> would be the following:
$xmlPath = "$env:appveyor_build_folder\MyProject\MyProject.csproj"
$xml = [xml](get-content $xmlPath)
$propertyGroup = $xml.Project.PropertyGroup | Where { $_.Version}
$propertyGroup.Version = $env:appveyor_build_version
$xml.Save($xmlPath)