feat: 解决共享框架的问题

main
bicijinlian 1 year ago
parent 28ad4d2fa8
commit 1ee04d29a2

@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<ProjectReference Include="..\AuthStudy.Authentication.Shared\AuthStudy.Authentication.Shared.csproj" />
</ItemGroup>

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AuthStudy.Authentication.Basic
{
internal class BasicAuthenticationDefaults
{
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AuthStudy.Authentication.Basic
{
internal class BasicAuthenticationExtensions
{
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace AuthStudy.Authentication.Basic
{
internal class BasicAuthenticationHandler
{
}
}

@ -0,0 +1,13 @@

using Microsoft.AspNetCore.Authentication;
namespace AuthStudy.Authentication.Basic
{
public class BasicAuthenticationOptions : AuthenticationSchemeOptions
{
public BasicAuthenticationOptions()
{
}
}
}

@ -1,7 +0,0 @@
namespace AuthStudy.Authentication.Basic
{
public class Class1
{
}
}

@ -7,8 +7,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Abstractions" Version="2.2.0" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Authorization" Version="7.0.5" />
<PackageReference Include="Microsoft.Extensions.Features" Version="7.0.5" />
<PackageReference Include="UAParser" Version="3.1.47" />

@ -20,6 +20,9 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "授权", "授权", "{74577ADF-0E82-4798-8D49-AA70DD82528A}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Docs", "Docs", "{947159C1-414A-4927-A77B-7A37C8A20BDD}"
ProjectSection(SolutionItems) = preProject
Docs\说明.md = Docs\说明.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution

@ -0,0 +1,80 @@
说明
====
## 关于 共享框架
随着 .NET Core 3.0 的发布,许多 ASP.NET Core 程序集不再作为包发布到 NuGet。
相反,程序集包含在 Microsoft.AspNetCore.App 共享框架中,该框架随 .NET Core SDK 和运行时安装程序一起安装。
+ Web项目一般自动包含 AspMicrosoft.AspNetCore.App 共享框架,即 共享框架由项目的Sdk属性Microsoft.NET.Sdk.Web自动引入
```xml
<Project Sdk="Microsoft.NET.Sdk.Web">
<!--共享项目由上面Sdk类型Microsoft.NET.Sdk.Web自动引入-->
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<!--Nuget包引用-->
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<!--项目引用-->
<ProjectReference Include="..\xx.csproj" />
</ItemGroup>
</Project>
```
+ 类库项目等,要手动引入(无法使用nuget包的方式引入)
```xml
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<!-- 手动引入共享框架(不指定版本,自动跟随项目版本),多目标项目,也可以使用变量根据目标选择引入-->
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup>
<!--Nuget包引用-->
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.5" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.4.0" />
</ItemGroup>
<ItemGroup>
<!--项目引用-->
<ProjectReference Include="..\xx.csproj" />
</ItemGroup>
</Project>
```
```xml
<!-- 多目标示例-->
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0</TargetFrameworks>
<PackageTags>aspnetcore;authentication;security;basicauth</PackageTags>
<Configurations>Debug;Release;CodeQL</Configurations>
</PropertyGroup>
<!-- netstandard2.0 版本引入老版本的包(Microsoft.AspNetCore.Authentication等) -->
<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
<PackageReference Include="Microsoft.AspNetCore.Authentication" Version="2.0" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.0" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.0" />
</ItemGroup>
<!-- 高版本手动引入共享框架Microsoft.AspNetCore.App由共享框架引入模块 -->
<ItemGroup Condition="'$(TargetFramework)' != 'netstandard2.0'">
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
</Project>
```
Loading…
Cancel
Save