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

3

这是一个Windows Phone 7项目。

由于某种奇怪的原因,Visual Studio 2010不允许我在项目设置的应用程序选项卡中将目标.NET版本设置为.NET 4.0。它被禁用了。

当我编译项目时,XNA程序集是.NET 4.0,但System和System.Core以及其他所有内容都是.NET 2.0。

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

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

编辑:我的最终目标是使其编译。为什么它选择使用.NET 2.0作为System程序集?

编辑:我收到以下错误:

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".

编辑:好的,我已经移除了那些有问题的XNA组件。事实证明我不需要它们。现在编译器又出现了这个错误:

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

Compile complete -- 1 errors, 0 warnings

你尝试过手动编辑 csproj 文件吗? - Mrchief
我应该如何编辑它? - 101010
在记事本或任何文本编辑器中打开.csproj文件,查找TargetFrameworkVersion标签。示例:<TargetFrameworkVersion>v4.0</TargetFrameworkVersion> - Mrchief
WP7项目的默认TargetFrameworkVersion已经是4.0,但这并不意味着您可以使用.NET 4.0程序集。这是不被支持的。 - Claus Jørgensen
3个回答

5
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 - mscorlib - 2.0.5.0 - System.* - 2.0.5.0

你很可能添加了PC版本的XNA框架引用,而不是手机版本。你需要发布你的.csproj文件以获取更详细的帮助。 - Claus Jørgensen
此外,您的引用未列为 Phone 7 平台支持的内容(例如:http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.media.video.aspx)。 - Claus Jørgensen

1
Windows Phone 使用 Silverlight(7.0 用 Silverlight 3,Mango 用 Silverlight 4),其中并非运行完整的 .NET CLR,而是使用 .NET CLR 的子集(请参见 MSDN 上的 Windows Phone 上的 Silverlight, Silverlight 架构)。因此,您不能引入 .NET 4.0 程序集甚至完整的 .NET 2.0 程序集。
您可以看到的 2.0.5.0 版本号是特殊的 Silverlight 版本号,这些实际上并不是完整的 .NET 2.0 程序集。
然而,这意味着您可以将一些 Silverlight 程序集添加到 Windows Phone 中(例如,这是 Silverlight 单元测试框架的做法)。如果您这样做,那么您会收到一个警告,即不是所有桌面版 Silverlight 都支持 Windows Phone。您只应小心地这样做,因为可能会出现问题...

-2
请检查您是否正在使用.NET框架或.NET框架客户端配置文件。如果是客户端配置文件,请将其更改回.NET框架。

没有针对Phone 7项目的这种东西。 - Claus Jørgensen

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接