简体   繁体   English

全球Assemby参考?

[英]Global assemby reference?

I'm new to C# and ASP.Net core. 我是C#和ASP.Net核心的新手。

I'm using ASP.Net core 1.1 and I have referenced a project, how can I make this referenced project globally visible to all controlles, so I don't have to type "using MyReference" in all controllers? 我正在使用ASP.Net core 1.1,并且已经引用了一个项目,如何使该引用的项目对所有控件全局可见,因此我不必在所有控制器中都键入“ using MyReference”?

I tried adding it to my csproj file under <Reference Include="MyReference" /> but it still wants me to add "using..." in the controller. 我尝试将其添加到<Reference Include="MyReference" />下的csproj文件中,但它仍然希望我在控制器中添加“ using ...”。

How can I make it globally? 如何在全球范围内制作?

Thanks 谢谢

As far as I know, there is no way to do that. 据我所知,没有办法做到这一点。 You can do it for views (ie. .cshtml files) by including it in the _ViewImports.cshtml file like so: 您可以通过将其包含在_ViewImports.cshtml文件中来对视图(即.cshtml文件)进行处理,如下所示:

 @using MyReference

But for .cs files I don't think there is any way to do that. 但是对于.cs文件,我认为没有任何方法可以做到。 You will need to include the using at the top of each file. 您将需要在每个文件的顶部包含using。 If you are using Visual Studio, you can automate this by modifying the default template for your code so that when you start a new code file it's automatically in there since you made it part of the template. 如果您使用的是Visual Studio,则可以通过修改代码的默认模板来自动执行此操作,以便在启动新的代码文件时,由于将其作为模板的一部分,因此该文件自动在其中。 If you are not using Visual Studio, many other editors have this same feature, so look into their docs on how to modify the code file template. 如果您不使用Visual Studio,那么许多其他编辑器都具有相同的功能,因此请查看其文档,以了解如何修改代码文件模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM