简体   繁体   English

试图用monogame项目和类库创建解决方案,但不允许我在它们之间添加引用

[英]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.

相关问题 尝试使用swig将C ++库与C#链接-不会让我添加对将dll转换为C#项目的引用 - Trying to link C++ library with C# using swig - will not let me add reference to resulging dll to C# project Asp.Net网站不允许我添加参考类库。 已经存在 - Asp.Net website won't allow me to add reference class library. Already exists 不会让我使用秒表类。 在视觉工作室 - Won't let me use the class Stopwatch. in visual studio 无法在VS2012中添加新的monogame内容项目到解决方案 - Can't add new monogame content project to solution in VS2012 Visual Studio解决方案资源管理器不允许我使用/查看新的.xaml文件 - Visual Studio Solution Explorer won't let me use / see new .xaml files 无法在同一解决方案中为WCF项目的客户端类添加服务引用 - Can't add service reference to client class for WCF project within same solution 为什么我不能将类库项目引用添加到Silverlight项目? - Why I can't add a class library project reference to a Silverlight project? 我收到此错误,如果可能,需要帮助修复它。我正在尝试构建我的项目以查看 output 但它不会让我 - I'm getting this error and need help fixing it if possible.I'm trying to build my project to see the output but it won't let me DataBinding不会让我更改值 - DataBinding won't let me change the value 为什么不让我通过此列表? - Why won't it let me pass this list?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM