如何使Visual Studio 2010在Windows Phone项目上使用.NET 4.0而不是.NET 2.0?

问题描述:

这是一个Windows Phone 7项目。如何使Visual Studio 2010在Windows Phone项目上使用.NET 4.0而不是.NET 2.0?

由于一些奇怪的原因,Visual Studio 2010不允许我在项目设置“应用程序”选项卡中将目标.NET版本设置为.NET 4.0。它变灰了。

当我编译项目时,XNA程序集是.NET 4.0,但系统和System.Core,其余都是.NET 2.0。

当我说“添加引用”时,它不会让我选择任何.NET 4.0系统程序集,如mscorlib。

我卸载了.NET 4.0,然后重新安装它。没有帮助。

编辑:我的最终目标是让这个编译。为什么它为系统程序集选择.NET 2.0?

编辑:我得到这些错误:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "Microsoft.Xna.Framework.Video" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0,Profile=Client". To resolve this problem, either remove the reference "Microsoft.Xna.Framework.Video" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089". 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "Microsoft.Xna.Framework.Net" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0,Profile=Client". To resolve this problem, either remove the reference "Microsoft.Xna.Framework.Net" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089". 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "Microsoft.Xna.Framework.Avatar" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0,Profile=Client". To resolve this problem, either remove the reference "Microsoft.Xna.Framework.Avatar" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089". 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "Microsoft.Xna.Framework.Storage" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0,Profile=Client". To resolve this problem, either remove the reference "Microsoft.Xna.Framework.Storage" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089". 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "Microsoft.Xna.Framework.Xact" could not be resolved because it has an indirect dependency on the framework assembly "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0,Profile=Client". To resolve this problem, either remove the reference "Microsoft.Xna.Framework.Xact" or retarget your application to a framework version which contains "mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089". 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "Microsoft.Xna.Framework.Net" could not be resolved because it has an indirect dependency on the framework assembly "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0,Profile=Client". To resolve this problem, either remove the reference "Microsoft.Xna.Framework.Net" or retarget your application to a framework version which contains "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089". 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "Microsoft.Xna.Framework.Xact" could not be resolved because it has an indirect dependency on the framework assembly "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0,Profile=Client". To resolve this problem, either remove the reference "Microsoft.Xna.Framework.Xact" or retarget your application to a framework version which contains "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089". 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "Microsoft.Xna.Framework.Xact" could not be resolved because it has an indirect dependency on the framework assembly "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0,Profile=Client". To resolve this problem, either remove the reference "Microsoft.Xna.Framework.Xact" or retarget your application to a framework version which contains "System.Core, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089". 
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1360,9): warning MSB3268: The primary reference "Microsoft.Xna.Framework.Xact" could not be resolved because it has an indirect dependency on the framework assembly "Microsoft.VisualC, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0,Profile=Client". To resolve this problem, either remove the reference "Microsoft.Xna.Framework.Xact" or retarget your application to a framework version which contains "Microsoft.VisualC, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". 

编辑: OK,我删除了这些问题的XNA组件。事实证明,我不需要他们。现在编译器回到这个错误:

error CS0518: Predefined type 'System.Object' is not defined or imported 

Compile complete -- 1 errors, 0 warnings 
+0

你试过手动编辑csproj文件吗? – Mrchief

+0

我该如何编辑它? – 010110110101

+0

在记事本或任何文本编辑器中打开.csproj文件并查找此“TargetFrameworkVersion”标签。示例:' v4.0 TargetFrameworkVersion>'。 – Mrchief

Visual Studio向您显示正确的程序集。您无法选择Windows Phone 7的.NET 4.0程序集,原因很简单,Windows Phone 7不运行.NET 4.0。

你看到的版本应该是这样的:。

  • Microsoft.Phone * - 7.0.0.0
  • Microsoft.XNA * - 4.0.0.0
  • mscorelib - 2.0.5.0
  • System。* - 2.0.5.0
+0

我添加了我收到的错误。 – 010110110101

+0

您很可能会添加对XNA框架的PC版本的引用,而不是电话版本。您需要发布.csproj文件,以获取更详细的帮助。 –

+0

此外,您的引用未在Phone 7平台上列出为受支持(例如:http://msdn.microsoft.com/zh-cn/library/microsoft.xna.framework.media.video.aspx –

请检查您是否使用.NET框架或.NET框架客户端配置文件。如果它的客户端配置文件,将其更改回到.NET Framework。

+0

Phone 7项目没有这种东西 –

Windows Phone使用Silverlight(Silverlight 3 for 7.0,Silverlight 4 for Mango),它不运行完整的.NET CLR,但使用子集完整.NET CLR的详细信息(请参阅Silverlight on Windows Phone,Silverlight Architecture上的MSDN链接)。因此,您无法使用.NET 4.0程序集甚至完全.NET 2.0程序集。

您可以看到的2.0.5.0版本号是特殊的Silverlight版本号 - 这些实际上并不是完整的.NET 2.0程序集。

但是这意味着您可以将一些Silverlight程序集添加到Windows Phone中(这是您为Silverlight单元测试框架所做的实例)。如果你这样做,那么你会得到一个警告,说明Windows Phone并不支持所有的桌面Silverlight。你只应该小心这样做,因为事情可能会破坏...