[英]Trying to create a solution with a monogame project and a class library, and it won't let me add a reference between them
I wrote a game in XNA a while ago, it just has two projects - a game, and a library. 不久前我用XNA编写了一个游戏,它只有两个项目-一个游戏和一个库。 It worked fine, and now I am porting it to Monogame.
它工作正常,现在我将其移植到Monogame。
I have created a MonoGame Game project, and a Class Library, and put all of the files from my old XNA project into them. 我创建了一个MonoGame游戏项目和一个类库,并将旧XNA项目中的所有文件放入其中。 The Class Library builds with no problems or errors.
类库的构建没有问题或错误。 However, it won't let me add a reference to it from my other (game) project.
但是,它不允许我在其他(游戏)项目中添加对它的引用。
It just says "Unable to add a reference to [MyLibrary]" 它只是说“无法添加对[MyLibrary]的引用”
I read something about it possibly being because they target different frameworks - one targets .net and one targets ".net CORE" but I don't know if this is the case, or how to fix it. 我读到有关它的内容可能是因为它们针对的是不同的框架-一个针对.net,另一个针对“ .net CORE”,但我不知道是否是这种情况,或者如何解决。
Can anyone advise me on what I should do? 谁能建议我该怎么做?
You're probably right about the framework targeting issues. 您可能对框架定位问题是正确的。
There are a few ways to deal with this, the first is to try and change you're library to a Portable Class Library. 有几种解决方法,第一种是尝试将您的库更改为可移植类库。 They are designed to be able to target different frameworks including the different frameworks MonoGame supports.
它们旨在能够针对不同的框架,包括MonoGame支持的不同框架。 http://msdn.microsoft.com/en-au/library/gg597391.aspx
http://msdn.microsoft.com/en-au/library/gg597391.aspx
The downside of portable class libraries is that they only support a subset of the full .NET framework. 可移植类库的缺点是它们仅支持完整.NET框架的子集。 If that's the case you'll want to try and change you're library into a Mono for Android Library project (or whatever framework you're targeting).
如果是这种情况,您将尝试将您的库更改为Mono for Android Library项目(或您要定位的任何框架)。
If you want to build for multiple target frameworks and need to minimize the amount of duplicate code in each project I think your best bet is to add the files as 'links' to each projects. 如果您要针对多个目标框架进行构建,并且需要在每个项目中减少重复代码的数量,那么我认为最好的选择是将文件作为“链接”添加到每个项目。 It adds a bit of maintenance but allows you to edit a file in one project and have the change made across all projects.
它增加了一些维护,但允许您在一个项目中编辑文件并在所有项目中进行更改。
If I were you I avoid the Portable Class Library both for the reasons that @craftworkgames specifies, and also from my own experience of developing a Windows 8 App - they just cause you hassle. 如果您是我,我既会因为@craftworkgames指定的原因而避免了可移植类库,又因为我自己开发Windows 8 App的经验而避免了它们-但这只会引起您的麻烦。 While it's good from a design principle to separate your classes into a library of their own, I would just add them all to your development project (unless you're writing an API that you want the world to be able to use?)
从设计原则上讲,将您的类分成自己的库是有好处的,但我只是将它们全部添加到您的开发项目中(除非您正在编写一个您希望全世界都可以使用的API?)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.