Home > Software design >  How can I get ApplicationPartAttribute within .net5 class library?
How can I get ApplicationPartAttribute within .net5 class library?

Time:03-25

The task is not practical, it's just learning experiment.

I have .net5 app (which essentially is asp .net core app) which references onto neighboring project "WebControllers" which contains only Controller class.

WebControllers is .net5 class library into which I added reference to Microsoft.AspNetCore.Mvc.Core package. This package allows to create of working Controller object which is discovered by asp .net core infrastructure and which properly handles http requests.

Now I want inside my WebController objec create variable of ApplicationPartAttribute type. I tried doing this like that:

var aaa = new Microsoft.AspNetCore.Mvc.ApplicationParts.ApplicationPartAttribute("asd");

But Visual studio says to me that it don't know ApplicationPartAttribute class and it doesn't offer to use some namespace or add some package.

Let's go to the MSDN. MSDN about this type for .NET5 says:

  • Namespace: Microsoft.AspNetCore.Mvc.ApplicationParts
  • Assembly: Microsoft.AspNetCore.Mvc.Core.dll
  • Package: Microsoft.AspNetCore.App.Ref v5.0.0

Okay, let's try to install this package. Next errors are occured:

  • NU1213 The package Microsoft.AspNetCore.App.Ref 5.0.0 has a package type DotnetPlatform that is incompatible with this project.
  • Package 'Microsoft.AspNetCore.App.Ref 5.0.0' has a package type 'DotnetPlatform' that is not supported by project 'WebControllers'

Why these errors are occured is unclear to me because both projects are .net5 projects and Microsoft.AspNetCore.App.Ref v5.0.0 is designed for .NET 5.

The question is: how can I use ApplicationPartAttribute in .net5 class library?

CodePudding user response:

Add this code in your xxx.csproj file

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
</ItemGroup>
  • Related