在完整的.NET Framework中使用ServiceStack

时间:2018-09-11 22:40:28

标签: servicestack

以完整的.NET Framework为目标时,像csproj文件那样,我在ServiceStack上遇到一些奇怪的依赖性错误:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net472</TargetFramework>
    <AssemblyName>Tsl.Example</AssemblyName>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore.Cors" Version="2.0.0" />
    <PackageReference Include="ServiceStack" Version="5.2.1" />
    <PackageReference Include="ServiceStack.Admin" Version="5.2.1" />
    <PackageReference Include="ServiceStack.Admin.Core" Version="5.2.1" />
    <PackageReference Include="ServiceStack.Api.Swagger" Version="5.2.1" />
    <PackageReference Include="ServiceStack.Api.Swagger.Core" Version="1.0.44" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Tsl.Example.Data\Tsl.Example.Data.csproj" />
    <ProjectReference Include="..\Tsl.Example.Model\Tsl.Example.Model.csproj" />
    <ProjectReference Include="..\Tsl.Example.Service\Tsl.Example.Service.csproj" />
  </ItemGroup>
</Project>

以下是错误:

Severity    Code    Description Project File    Line    Suppression State
Error   CS0433  The type 'AppHostBase' exists in both 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'   Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\AppHost.cs   19  Active
Error   CS0115  'AppHost.Configure(Container)': no suitable method found to override    Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\AppHost.cs   39  Active
Error   CS0433  The type 'Container' exists in both 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587' Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\AppHost.cs   39  Active
Error   CS1729  'AppHostBase' does not contain a constructor that takes 2 arguments Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\AppHost.cs   29  Active
Error   CS0103  The name 'Plugins' does not exist in the current context    Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\AppHost.cs   45  Active
Error   CS0103  The name 'Plugins' does not exist in the current context    Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\AppHost.cs   47  Active
Error   CS0433  The type 'PostmanFeature' exists in both 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'    Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\AppHost.cs   47  Active
Error   CS0103  The name 'Plugins' does not exist in the current context    Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\AppHost.cs   48  Active
Error   CS0433  The type 'AdminFeature' exists in both 'ServiceStack.Admin, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack.Admin, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'  Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\AppHost.cs   48  Active
Error   CS0103  The name 'Plugins' does not exist in the current context    Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\AppHost.cs   49  Active
Error   CS0433  The type 'ValidationFeature' exists in both 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587' Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\AppHost.cs   49  Active
Error   CS0433  The type 'Licensing' exists in both 'ServiceStack.Text, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' and 'ServiceStack.Text, Version=5.0.0.0, Culture=neutral, PublicKeyToken=02c12cbda47e6587'   Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\Program.cs   13  Active
Error   CS1503  Argument 2: cannot convert from 'Tsl.Example.AppHost' to 'ServiceStack.AppHostBase' Tsl.Example C:\projects\sandbox\api.example.tso.auth.atalasoft\src\Tsl.Example\Startup.cs   51  Active

我可以定位到完整的.NET Framework并引用ServiceStack库吗?

1 个答案:

答案 0 :(得分:2)

如果要在经典ASP.NET 或HttpListener上运行,则应仅引用同时包含.NET Standard 2.0和.NET的主要"ServiceStack.Admin"软件包(即不带.Core后缀)。 NET Framework v4.5构建。在.NET Framework应用程序中,它将使用 .NET v4.5 框架版本。

如果要在.NET Framework上创建新的 ASP.NET Core 应用,则应reference .Core packages instead,其中仅包含 .NET Standard 2.0 构建.NET Framework应用程序可以使用在ASP.NET Core Apps中运行所需的.NET Standard版本。

我强烈建议从ASP.NET Core .NET Framework Templates中的一个开始,创建具有正确依赖性的工作项目:

$ npm install -g @servicestack/cli

$ dotnet-new web-corefx AcmeNetFx

您应该不要同时引用两者,也只能将所有软件包的相同版本号一起使用,即,不能将不建议使用的ServiceStack.Api.Swagger.Core软件包与v5.2.1程序集一起使用。

ServiceStack.Api.Swagger包含旧的v1.2 version of Swagger,您可能想引用ServiceStack.Api.OpenApi来实现newer Swagger 2.0/Open API specification

相关问题