Since upgrade to Visual Studio 2022 17.4.0, xunit tests are correctly displayed in test explorer, but they are not executed. They were correctly executed in previous versions. There is no error message.
We have "Tests in the group : 11". Results : 11 not executed.
Build is ok.
I'm using framework.net 4.8
Here is my project references
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.4.0" />
<PackageReference Include="Moq" Version="4.18.2" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.2.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Thanks.
Upgrading to VS Version 17.4.0.1 does not fix the problem.
upgrading to Framework 4.8.1 neither.
upgrading to latest version of xunit neither.
Restarting, clearing and rebuild neither.
Changing target processor to x64 or x86 or auto neither.
The workaround is to downgrade Xunit package to xunit.runner.visualstudio 2.4.1 (last version is 2.4.5). I also downgraded Xunit to 2.4.1. Then I restarted the solution and the tests are running. Thanks Jérôme P. for the trick.
Related
How do I fix this issue ? Unable to add PCL reference to my Unit Test Proj.
PCL proj is using framework NetStandardLib v2.1
Testing this, NUnit Test project doesn't let you switch between Framework and Core once you have created it. Perhaps because different PackageReferences are needed.
Safest fix is to create a new NUnit Test project. But this time, when it asks for target Framework, pick a .Net core one. Probably pick the highest number it offers (Core 3.1).
Then copy or move all your test source files into it.
Looking at a Framework Test Project vs a Core one, these are the lines that are different.
Framework:
<PropertyGroup>
<TargetFramework>net48</TargetFramework>
...
<ItemGroup>
<PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.16.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0"/>
</ItemGroup>
...
Core:
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
...
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="NUnit" Version="3.13.3" />
<PackageReference Include="NUnit3TestAdapter" Version="4.2.1" />
<PackageReference Include="NUnit.Analyzers" Version="3.3.0" />
<PackageReference Include="coverlet.collector" Version="3.1.2" />
</ItemGroup>
...
When I try to create a BitmapImage instance (under WinUI 3) I get an exception that a necessary class is not registered. This is taking place within Visual Studio 2022, within an xUnit based test project.
The line throwing the exception is simply:
var retVal = new BitmapImage();
Given how simple the line is I'm wondering if there's something wrong with my xUnit project setup. Here it is:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="FluentAssertions" Version="6.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MapLibraryWinApp\MapLibraryWinApp.csproj" />
</ItemGroup>
</Project>
Here's the project file for the library containing the code I'm trying to test:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
<Nullable>enable</Nullable>
<RootNamespace>J4JSoftware.MapLibrary</RootNamespace>
<AssemblyName>J4JSoftware.MapLibraryWinApp</AssemblyName>
<AssemblyTitle>Map Library (Windows Apps)</AssemblyTitle>
<Version>0.5.0</Version>
<Copyright>Copyright © Mark A. Olbert</Copyright>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.0.3" />
<PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22000.197" />
<PackageReference Include="Microsoft.AspNetCore.WebUtilities" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\J4JLogging\J4JLogging\J4JLogging.csproj" />
<ProjectReference Include="..\MapLibrary\MapLibrary.csproj" />
</ItemGroup>
</Project>
I thought perhaps the test project might need to contain the <UseWinUI> tag, but adding it did not solve the problem.
You need to run an actual packaged WinUI app or deploy the Windows App SDK runtime along with a non-MSIX-packaged app to be able to use the WinUI types.
I am afraid it's not as simple as simply referencing the WinUI code from a standalone testrunner app.
Please refer to this blog post for an example of how to set up an actual app that runs the tests. Or avoid creating UI specific stuff in your unit tests.
I got an assembly that builds and unit tests fine on my PC, but fails to test on the build PC. It has been failing for about a month. I've most likely done something wrong. Here is the response I get from the build server.
16:29:38 Project "xyz.Utilities.UnitTests.csproj": VSTest
16:29:40 Test run for C:\Bin\Release\net5.0-windows\xyz.Utilities.UnitTests.dll (.NETCoreApp,Version=v5.0)
16:29:40 Microsoft (R) Test Execution Command Line Tool Version 16.11.0
16:29:40 Copyright (c) Microsoft Corporation. All rights reserved.
16:29:40
16:29:40 Starting test execution, please wait...
16:29:40 A total of 1 test files matched the specified pattern.
16:29:41 An exception occurred while invoking executor 'executor://mstestadapter/v2': Could not load type 'Microsoft.VisualStudio.TestTools.UnitTesting.ClassCleanupBehavior' from assembly 'Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
16:29:41 Stack trace:
16:29:41 at Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.MSTestExecutor.RunTests(IEnumerable`1 sources, IRunContext runContext, IFrameworkHandle frameworkHandle)
16:29:41 at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.RunTestsWithSources.InvokeExecutor(LazyExtension`2 executor, Tuple`2 executorUriExtensionTuple, RunContext runContext, IFrameworkHandle frameworkHandle)
16:29:41 at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Execution.BaseRunTests.RunTestInternalWithExecutors(IEnumerable`1 executorUriExtensionMap, Int64 totalTests)
16:29:41
16:29:41
16:29:41 Test Run Failed.
16:29:41
16:29:41 Build FAILED.
16:29:41 0 Warning(s)
16:29:41 0 Error(s)
My project file is quite simple:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0-windows</TargetFramework>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<OutputPath>$(SolutionDir)\Bin\$(Configuration)</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
<CheckForOverflowUnderflow>true</CheckForOverflowUnderflow>
<OutputPath>$(SolutionDir)\Bin\$(Configuration)</OutputPath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="EasyTcp" Version="4.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.2.7" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.7" />
<PackageReference Include="coverlet.collector" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\xyz.Utilities\xyz.Utilities.csproj" />
</ItemGroup>
</Project>
I think it has something to do with the version of Visual Studio on the build server. We are running Teamcity. Does anyone have any clue?
Upgrade your nuget packages to the latest and it should fix your problem. I think you need 2.2.8 for MSTest.TestAdapter and MSTest.TestFramework.
I've upgraded as suggested and it works fine now.
I'm trying to reference a class library from a Blazor WebAssembly project but getting an error that Blazor WebAssembly projects cannot reference ASP.NET Core shared framework projects. I've tried changing the class library target to .Net Framework but that breaks it. I'm at a loss here. How do I get this class library referenced?
Class Library project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="5.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.9" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.9">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Piranha" Version="9.1.1" />
<PackageReference Include="Piranha.AspNetCore" Version="9.1.0" />
</ItemGroup>
</Project>
I'm trying to reference a class library from a Blazor WebAssembly project
WebAssembly supports a subset of .net[5/core]. And that subset does not inlcude the SqlServer classes.
The direct error may point at some other cause, it's not clear. But this setup is not going to work. All Database operations have to happen on the Server.
That is why we have the [x] asp.net core hosted option in the New Project wizard.
I'm working on a asp.net core MVC project. I need to add a view for a method of a controller. To do that, I right click on the body of the considered method and then choose Add View but the system shows me an error:
there was an error running the selected code generator: Package restore failed rolling back package changes MyProject.
I appreciate if anyone tells me how I can fix the issue.
I've been banging my head for a while with this. I resolved it by following these steps.
Make sure all Packages are exactly the same version! Even Patch versions seem to fail. So if your SQLite is 3.1.1 and you SQLServer is 3.1.2 it will fail
Open your csproj file and manually edit the versions of the packages to the exact same version. Currently its 5.0.3 for everything but I had Microsoft.VisualStudio.Web.CodeGeneration.Design at 5.0.2 and it was failing
Optional Step : delete these package from all projects
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="5.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration" Version="5.0.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
After you manually edit the csproj file, save it/them (make changes in all your csproj files btw)
I also did this step - Nuget Package Manager Settings -> Package Sources Unselect the local folder and only make sure the remote one is selected
Close Visual Studio 2019.
Delete .vs folder in the Solution folder.
Start Visual Studio again, set startup project etc.
Now try creating a scaffolder controller, it will install the packages again and should work!
I had been trying scaffolding identity with latest version of as provided below
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.7">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
</ItemGroup>
and I had been getting similar error for latest 2 days, I tried most of the solution but it didn't work out for me.
Later I created a new project and tried scaffolding and it worked, I checked .csproj of new project and configured my old one same as that and it worked for me.
Here is the version details if you wish to scaffold using latest versions.
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.7" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="5.0.7" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.6">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />
</ItemGroup>
may be it can help someone trying identity scaffolding with latest version(5.0.7).
Package restore failed rolling back package changes for 'MyProject'.
It seems trying to install Package(s) that is not compatible with netcore version of your app, which cause the issue.
To troubleshoot the issue, please try to check the detailed information in Output window, like below.
I don't know if this is specific to my case, but I had a problem when it didn't want to generate a api controller. Project ran, No errors, no issues. But it just didn't want to generate.
So what I did was I just rebuilt the solution and then the next time I ran the generator it showed a different error. forgot to write [keyless] on top of my class. I fixed that and then ran the generator again, and it worked like a charm.