为什么我不能使用Microsoft.AspNetCore.Mvc;在我的单元测试项目中?

问题描述 投票:0回答:1

我创建了一个asp.net核心mvc项目,还创建了一个单元测试项目以下是单元测试项目的代码:

using System;
using Microsoft.AspNetCore.Mvc;  // error, type or namespace is missing
using Xunit;

namespace Project.Tests
{
    public class UnitTest1
    { 

        [Fact]
        public void Test1()
        {
          ...
        }
    }
}

我不太明白,我曾经创建单元测试项目时没有任何问题,为什么这次我无法访问Microsoft.AspNetCore.Mvc

c# .net xunit.net
1个回答
0
投票

您不能在单元测试项目中访问Microsoft.AspNetCore.Mvc,因为单元测试项目是一个单独的项目,并且其中不包含库Microsoft.AspNetCore.Mvc

要解决此问题,请将此程序集的引用添加到您的项目中。

© www.soinside.com 2019 - 2024. All rights reserved.