PostSharp Detected .NET Core SDK 7 - .net-6.0

I have a project targeting NET 6.0 framework.
When I build the project, I’m getting this message
Warning
Detected .NET Core SDK 7.0.100. This SDK version was not tested on this version of PostSharp. Using it may result in a build failure. Supported SDK versions are 2.1.500 to 6.0 (any revision).
Here is my project file
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AssemblyName>$(MSBuildProjectName)</AssemblyName>
<RootNamespace>$(MSBuildProjectName.Replace(" ", "_"))</RootNamespace>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="PostSharp.Patterns.Model" Version="6.10.16" />
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0">
<TreatAsUsed>true</TreatAsUsed>
</PackageReference>
</ItemGroup>
</Project>
Building project in visual studio 2022

You can update PostSharp to version 2023.0.3. It supports .NET 7 SDK.
The fact that your project targets .NET 6 doesn't imply that .NET 6 SDK is going to be used to build your project. By default, the highest installed SDK is used, unless you configure otherwise using global.json configuration file.

Related

Unable to install Swagger 6.2.3 for dotnet 6.0

Am unable to resolve nuget error in a new webapi project on one of my laptop, but works good on another. Both have same VS Code, nuget, dotnet core versions and have the same project files
error NU1100: Unable to resolve 'Swashbuckle.AspNetCore (>= 6.2.3)' for 'net6.0'.
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
</Project>
Any thoughts appreciated.
Check if NuGet sources are available via dotnet nuget list source.
Add it, if missing, via:
dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
See https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-nuget-add-source

Visual Studio New project wont run tests

Visual Studio 2019 is not detecting or discovering NUNit nor MSTest unit tests at all. I installed it fresh just a week ago. The MS guide here https://learn.microsoft.com/en-us/visualstudio/test/getting-started-with-unit-testing?view=vs-2019&tabs=mstest does not work.
A few threads hold possible solutions, but none that I've tried helped have helped. I'm new to C# so much of the steps have taken a long time to figure out, but while my application is progressing nicely I really want to work and learn in a TDD style.
Even if a create a new blank MSTest project, with no application code or libs in the solution at all, the example/template project does not work, so I'm missing something big someplace. (I have .NET Core SDKs installed - my intent is to target macOS and linux at a future point.)
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.13.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
</ItemGroup>
</Project>
Threads I have tried: Tests not running in Test Explorer Why will Visual Studio 2019 will not run my unit tests? Visual Studio 2019 Test Explorer puts all tests under "Not Run Tests"
If I create a project targeting .NET 4.7 all is good, it's when I want to target Core that I'm unstuck, if that helps.
Stuck again
I had to install a component called "NUnit 3", https://marketplace.visualstudio.com/items?itemName=NUnitDevelopers.NUnitTemplatesforVisualStudio worked for a moment... but when I added a testcase, it all broke again.
Did the nuget package updates, still not working.
I cloned. from git this project https://github.com/dotnet/samples/tree/master/core/getting-started/unit-testing-using-nunit
And it does not work either.
I then re-installed 2019, and emailed my project to a friend, who merely removed the nunit nuget modules, added them back and then it worked for him, but the project he sent me back did not work. Module versions unchanged
I opened the same project in the Microsoft developer VM/iso image and the project works just fine. so it's my environment that is incompatible with nunit somehow. Is there a way to see some traces?
Changed the installation drive from D: to C: I get this error now
Testhost process exited with error: A fatal error occurred, the required library hostfxr.dll could not be found.
If this is a self-contained application, that library should exist in [C:\Users\zapho\src\c#\tutorials\working\ConsoleApp1\ConsoleApp1\NUnit.Tests2\bin\Debug\netcoreapp3.1\].
If this is a framework-dependent application, install the runtime in the default location [C:\Program Files\dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location.
. Please check the diagnostic logs for more information.
Testhost process exited with error: A fatal error occurred, the required library hostfxr.dll could not be found.
If this is a self-contained application, that library should exist in [C:\Users\zapho\src\c#\tutorials\working\ConsoleApp1\ConsoleApp1\NUnit.Tests2\bin\Debug\netcoreapp3.1\].
If this is a framework-dependent application, install the runtime in the default location [C:\Program Files\dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location.
. Please check the diagnostic logs for more information.
You need to add the Microsoft.NET.Test.Sdk NuGet package to your solution to run tests in Visual Studio.
Modify your project file,
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="nunit" Version="3.13.0" />
<PackageReference Include="NUnit3TestAdapter" Version="3.17.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.9.1" />
</ItemGroup>
</Project>
Fixed it by eventually setting environment variable
DOTNET_ROOT=D:\Program Files\dotnet\
as per an answer
https://stackoverflow.com/a/61453119/337598

Nuget version mismatch for Microsoft.AspNetCore.Mvc.ViewFeatures when using metapackage

I migrated an ASP.NET Core project from .NET Framework to .NET Core and in the process replaced the AspNetCore nuget packages with the Microsoft.AspNetCore.App metapackage. Originally I specified a version for it which worked fine, but VS whined about that telling me I'm not supposed to specify a version, so I removed it. Once I did that this happened:
'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' which has a higher version than referenced assembly 'Microsoft.AspNetCore.Mvc.ViewFeatures' with identity 'Microsoft.AspNetCore.Mvc.ViewFeatures, Version=2.0.0.0,
These are coming from a Unit Test project which references my ASP.NET Core project. The ASP.NET Core project builds fine on its own. Now, I understand what this error means - somewhere in this Test project I must be referencing this package with a different version than what is provided by the metapackage. What I want to know is where is this package being referenced in my Test project? I have the following nuget packages in the Test project:
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="2.2.4" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="Moq" Version="4.10.1" />
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
</ItemGroup>
I don't see where any of these packages use any AspNetCore dependencies, so I'm at a loss as to where the version mismatch could be.

ASP.NET Core (NET Framework) Teamcity build fails, VS builds properly

I have an ASP.NET Core project that builds properly with VS but fails with TeamCity.
It is a project that compiles to a library, but TeamCity tries to build it as an executable, and complains about the lack of 'main':
CSC error CS5001: Program does not contain a static 'Main' method suitable for an entry point
The content of the .csproj file are as follow:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<OutputType>Library</OutputType>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net462</TargetFramework>
<RuntimeIdentifier>win7-x86</RuntimeIdentifier>
<OutputTypeEx>library</OutputTypeEx>
<StartupObject />
<AssemblyName>Test</AssemblyName>
<RootNamespace>Test</RootNamespace>
</PropertyGroup>
<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
</ItemGroup>
</Project>
Visual studio has no problem building the dll file.
To reproduce:
Create an ASP.NET Core (.NET Framework) project
Change the output type to library
Remove the program.cs / startup.cs files
Compile with Visual Studio to confirm a library is being built
Build with Team City and an error will appear
To avoid that error, Please look into this SO post or this
You should be using the dotnet core plugin or you can easily
configure dotnet build command(if dotnet is present in your build
servers).
Or you can refer the MusicStore build.cmd file for reference. This basically downloads and installs the dotnet and all the dependencies and then builds the project.
Hope it helps!
I found a workaround; in the project file, VS puts this:
<OutputTypeEx>library</OutputTypeEx>
I need to add one line:
<OutputType>Library</OutputType>
<OutputTypeEx>library</OutputTypeEx>
So it looks like the build with TeamCity is not handling the OutputTypeEx propery but it handles the OutputType one.
I still see this as a bug, but at least there is a workaround.

Reference system nuget from .net standard library

I tried adding some standard nugets to my .Net standard 2.0 library project. But when compiling I get the following type of errors:
The type 'IDisposable' exists in both 'System.Runtime, Version=4.1.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and
'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
and
Predefined type 'System.Object' is not defined or imported
Here is my project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.Net.WebSockets" Version="4.3.0" />
<PackageReference Include="System.Threading.Tasks.Dataflow" Version="4.7.0" />
</ItemGroup>
</Project>
Both nugets declare support for .Net Standard. I used VS 15.3 preview 2.
Is there some magic setting for .Net Standard 2.0 libraries I need to be aware of? What do I need to do to get a .Net standard 2.0 library compiling?
This happens due to a bug in the conflict resolution targets / infrastructure that is fixed in current 2.0.0-preview2 builds. These aren't included in VS 2017 15.3 preview 2.0 and need to be installed separately (e.g. from the links in https://github.com/dotnet/cli/tree/release/2.0.0).
Note that VS 2017 15.3 now uses an "SDK resolver" that looks for a global.json in the opened project and uses the SDK version it resolves to (or latest) instead of the bundled SDKs.

Resources