将项目添加到解决方案时,如何使Visual Studio自动添加引用?

时间:2021-10-31 02:22:29

Programming is (so far) just a hobby for me, so I try to find ways to improve, learn some basic algorithms and programming skills that might come in handy in the future. Currently I'm working my way though Project Euler and solving the puzzles there.

编程(到目前为止)只是我的一个爱好,所以我试图找到改进的方法,学习一些可能在将来派上用场的基本算法和编程技巧。目前我正在通过Project Euler工作并解决那里的难题。

I'm working in C#, and have set up a solution named ProjecEuler in which I add one new Console Application Project for each problem. (I know, maybe not the ultimate setup considering memory efficiency and such, but it's easy to do and easy to run, and I'm only doing this for myself...)

我在C#工作,并设置了一个名为ProjecEuler的解决方案,我在其中为每个问题添加一个新的控制台应用程序项目。 (我知道,考虑到内存效率等等,可能不是最终的设置,但它很容易操作并且易于运行,而且我只为自己做这个...)

However, as the problems became more complex, I found myself reusing the same code over and over time, so I added a ClassLibrary project in which I put useful code that I might want in several projects. But each time I add a new project to the solution, I have to manually add a reference to the class library. As I add a couple of projects per work hour on this, it gets quite tedious.

然而,随着问题变得越来越复杂,我发现自己一遍又一遍地重复使用相同的代码,所以我添加了一个ClassLibrary项目,其中我在几个项目中放置了我可能需要的有用代码。但每次我向解决方案添加一个新项目时,我都必须手动添加对类库的引用。由于我在每个工作小时添加了几个项目,因此非常繁琐。

Is there any way to tell Visual Studio that I want all the projects in the solution to inherit the class library, and have VS add the references automagically?

有没有办法告诉Visual Studio我希望解决方案中的所有项目都继承类库,并让VS自动添加引用?

1 个解决方案

#1


Yes. You can create a console project, add all refereces you need and then export it (File > Export Template) as a Project Template. After this, your project template will be available in Visual Studio.

是。您可以创建一个控制台项目,添加所需的所有引用,然后将其导出(文件>导出模板)作为项目模板。在此之后,您的项目模板将在Visual Studio中可用。

This VS feature is really useful, you can customize many aspects of you template. I ecourage you spend some time playing with that!

这个VS功能非常有用,您可以自定义模板的许多方面。我鼓励你花一些时间玩这个!

Hope this helps!

希望这可以帮助!

#1


Yes. You can create a console project, add all refereces you need and then export it (File > Export Template) as a Project Template. After this, your project template will be available in Visual Studio.

是。您可以创建一个控制台项目,添加所需的所有引用,然后将其导出(文件>导出模板)作为项目模板。在此之后,您的项目模板将在Visual Studio中可用。

This VS feature is really useful, you can customize many aspects of you template. I ecourage you spend some time playing with that!

这个VS功能非常有用,您可以自定义模板的许多方面。我鼓励你花一些时间玩这个!

Hope this helps!

希望这可以帮助!