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>
Related
I have an Azure Function which run on .net core 3.1, but when i change the .net version from 3.1 to 7 i got this error:-
System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Extensions.Configuration.Abstractions, Version=7.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.'
here is a screen shot:-
here is my csproj file:-
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.15.0" />
<PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.11" />
<PackageReference Include="PnP.Core.Auth" Version="1.8.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
Any advice on this please?
I have installed Install-Package Microsoft.Extensions.Configuration.Abstractions -Version 7.0.0 but this did not fix the issue either.
.NET 3.1 is in-process and .NET 7 is Isolated Worker Process type.
I can see your .csproj file code given in the question that you changed only .NET Framework and Azure Functions Version which is not complete configuration code for .NET 7 Isolated Process Azure Function and also you're missing few Function Worker package references in the .csproj file code.
Basic/Default .NET 7 Isolated Azure Functions Project contains the below code in .csproj file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.8.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Http" Version="3.2.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
.NET 7 In-Process is not yet released and to convert from .NET 3.1 (In-Process Model) to .NET 7 (Isolated Worker Process), you need to write the .NET 7 Isolated Compatible NuGet Packages, code changes in the Function Code, program.cs file, etc.,
Refer to this MS Doc for Migration Steps & Checks of Azure Functions V3 to V4 and One of the my answers SO #74428448 states the update of the supported available version in Azure Functions C#.
I have a web app solution that is quite old where the main project is Asp.Net 4.6 and a small companion project is .Net Core 2.
I want to first upgrade them both to .Net Core 3.1, and then upgrade to .Net 7 later this year.
According to the Microsoft documentation I have to update the target framework and associated libraries.
So I updated this part in my project file:
<TargetFramework>netcoreapp3.1</TargetFramework>
However, the other referenced libraries don't seem to have 3.1 updates. How would I upgrade these?
<PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.SpaServices" Version="2.0.3" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="2.0.2" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.3" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.ServiceModel.Duplex" Version="4.3.0" />
<PackageReference Include="System.ServiceModel.Security" Version="4.3.0" />
Thanks!
When Microsoft introduced .NET Core 3.0, they stopped producing a large number of NuGet packages (If you're interested, you can see the list here).
Microsoft made them part of the shared framework Microsoft.AspNetCore.App that is implicitly referenced if your .csproj targets Microsoft.NET.Sdk.Web SDK. You can check this in your .csproj project.
<Project Sdk="Microsoft.NET.Sdk.Web">
...
</Project>
If your project targets Microsoft.NET.Sdk, then you might have to add a FrameworkReference, as explained here.
Assuming the latter is not your case, removing the references to those NuGet packages should be fine.
For microsoft .net core packages,I think you could search in the document and found the correspond packages.
https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore?view=aspnetcore-2.2
example1:
example2:
I have an ASP.NET Core project targeting net4.6.1
The following error is thrown every time I try to start the project with debugging, from both VS2017 and command line using dotnet run.
The csproj is the following:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net461</TargetFramework>
<Platforms>x64</Platforms>
<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
<AspNetCoreModuleName>AspNetCoreModule</AspNetCoreModuleName>
<StartupObject></StartupObject>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.HttpsPolicy" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.2.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\pathToAnotherProject\myproject.csproj" />
</ItemGroup>
</Project>
I can mention that I have a single startup project created as an ASP.NET Core project and multiple .net core class library projects targeting net461.
Any idea where the problem comes from?
Have you tried to enable 'use managed compatibility mode' in the debugging>general section of VS2017 options.
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 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.