代码之家  ›  专栏  ›  技术社区  ›  Brian Ogden

将ServiceStack与完整的.NET Framework结合使用

  •  1
  • Brian Ogden  · 技术社区  · 7 年前

    针对完整的.NET Framework时,我在ServiceStack中遇到了一些奇怪的依赖性错误,例如csproj文件:

    <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
    

    1 回复  |  直到 7 年前
        1
  •  2
  •   mythz    7 年前

    如果你想继续跑 经典ASP.NET 或者HttpListener,您应该只引用 "ServiceStack.Admin" .NET 4.5版

    如果你想创建新的 ASP.NET核心 .NET Framework上的应用程序 reference .Core packages instead .NET标准版2.0 强制.NET Framework应用程序使用运行所需的.NET标准生成的生成ASP.NET核心应用。

    我强烈建议从一个 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 .

    推荐文章