IEndpointRouteBuilder找不到接口,找不到接口

时间:2020-01-23 07:48:58

标签: asp.net routing core

我有

NuGet Microsoft.AspNetCore.Http.Abstractions
NuGet Microsoft.AspNetCore.Routing

并使用名称空间

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Routing;

我想构建类似这样的东西,但是它似乎不知道IEndpointConventionBuilder或IEndpointRouteBuilder,并且拒绝编译。

public static class EndpointRouteBuilderExtensions
{
    public static IEndpointConventionBuilder MapServiceEndpoints(this IEndpointRouteBuilder endpoints)
    {

       //some code
    }
}

我想念什么...?

3 个答案:

答案 0 :(得分:3)

从.NET Core 3.0开始,您需要在csproj文件中设置Framework引用。

更改

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

收件人

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

有关更多信息,请参见Microsoft's migration guide

答案 1 :(得分:3)

如果要创建ASP.NET Core库,则需要在项目文件中包括FrameworkReference,如下所示:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp3.0</TargetFramework>
  </PropertyGroup>

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

</Project>

答案 2 :(得分:0)

因此,在浏览.net框架后,我找到了解决方法,并访问了构建器中的后备存储


router.get('/thumbnail/:name/:fontsize/:color/:posx/:posy', function (req, res, next) {
  let name = req.params.name;
  let fontsize = req.params.fontsize
  let positionx = req.params.posx 
  let positiony = req.params.posy
  let color = req.params.color

  let myimage = 'static/image1.jpg'

  const canvas = createCanvas(2000, 1000)
  const ctx = canvas.getContext('2d')
  var str = "hi "+name
  registerFont('AvenirNext.ttf', { family: 'Avenir Next' })
  loadImage(myimage).then((image) => {
  ctx.drawImage(image, 0 , 0, 2000, 1000);
  ctx.font = fontsize + "px Avenir Next"
  ctx.fillStyle = color
  ctx.fillText(str, positionx, positiony);

  const out = fs.createWriteStream(__dirname + '/test.jpeg')
  const stream = canvas.createJPEGStream()
  stream.pipe(res)
  out.on('finish', () =>  console.log('The JPEG file was created.'))

})
});

此后,您已经配置了所有端点并添加了自己的端点。