如何从另一个项目引用ASP.NET 5项目?

编程入门 行业动态 更新时间:2024-10-27 16:26:42
本文介绍了如何从另一个项目引用ASP.NET 5项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个从VS2015中的ASP.NET 5预览模板创建的Web应用程序项目。它运行在dnx 1.0.0-beta7上,但是我使用的是完整的.NET框架而不是.NET Core。

在同一解决方案中,我有一个NUnit类库项目,但在此处尝试将Web项目添加为参考时,Visual Studio表示无法添加对'...'的参考。

是有解决方法吗?还是对ASP.NET vNext应用程序进行单元测试的首选方法是什么?

解决方案

最简单的方法是确保ASP .NET 5 Web项目和测试项目共享一个公共父目录。例如:

解决方案 |-Web | |-project.json |-测试 | |-project.json

这样Roslyn将能够解析不同子目录中的符号。 / p>

当然,您还需要将 Tests 项目中的依赖项添加到 Web 项目在 Tests\project.json 文件中:

{ webroot: wwwroot, version: 1.0.0- *, dependencies:{ Web : 1.0.0- * }, frameworks:{ dnx451:{}, dnxcore50:{} } }

如果他们没有共同的父目录,则可以始终在根目录中添加 global.json 文件,并在其中包含包含源代码的子目录。

解决方案 |-global.json |-Web | |-project.json |-测试 | |-project.json

其中 global.json 包含:

{源:[网络,测试] }

在Visual Studio 2015中使用添加引用

如果使用Visual Studio 2015中的添加引用对话框从 ASP.NET 5 Web 项目引用类库项目,则会出现此错误:

无法添加对< ProjectName> 的引用。

这意味着您要引用的项目不是 DNX 项目,而是普通的 Class Library 项目。您需要确保该类库是一个 ASP.NET类库(包)项目,以便对其进行引用。

I have a Web Application project created from ASP.NET 5 Preview Templates in VS2015. It is running on dnx 1.0.0-beta7, but I'm using full .NET framework rather than .NET Core.

Within the same solution I have a NUnit class library project, but when trying to add the web project as a reference here, Visual Studio says "A reference to '...' could not be added."

Is there a workaround for this? Or what is the preferred way of unit testing ASP.NET vNext applications?

解决方案

The easiest way is to make sure that your ASP.NET 5 web project and the test project share a common parent directory. For example:

Solution |-- Web | |-- project.json |-- Tests | |-- project.json

That way Roslyn will be able to resolve the symbols across different subdirectories.

Of course, you'll also need to add a dependency from the Tests project to the Web project in the Tests\project.json file:

{ "webroot": "wwwroot", "version": "1.0.0-*", "dependencies": { "Web": "1.0.0-*" }, "frameworks": { "dnx451": { }, "dnxcore50": { } } }

If they can't have common parent directory, you can always add a global.json file in the root directory with the list of subdirectories that contain source code.

Solution |-- global.json |-- Web | |-- project.json |-- Tests | |-- project.json

where global.json contains:

{ "sources": ["Web", "Tests"] }

Using "Add Reference" in Visual Studio 2015

If when you reference a class library project from an ASP.NET 5 Web project using the Add Reference dialog in Visual Studio 2015 you get this error:

A reference to <ProjectName> could not be added.

It means that the project you're trying to reference isn't a DNX project but rather a normal Class Library project. You need to make sure that the class library is an ASP.NET Class Library (Package) project in order to reference it.

更多推荐

如何从另一个项目引用ASP.NET 5项目?

本文发布于:2023-11-05 21:27:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1561902.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   ASP   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!