【问题标题】:How to make Visual Studio 2010 use .NET 4.0 instead of .NET 2.0 on a Windows Phone project?如何让 Visual Studio 2010 在 Windows Phone 项目中使用 .NET 4.0 而不是 .NET 2.0?
【发布时间】:2011-07-22 01:20:50
【问题描述】:

这是一个 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 作为系统程序集?

编辑:我收到这些错误:

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文件吗?
  • 我应该以什么方式编辑它?
  • 在记事本或任何文本编辑器中打开 .csproj 文件并查找此 TargetFrameworkVersion 标签。示例:<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>.
  • WP7 项目的默认 TargetFrameworkVersion 已经是 4.0,但这并不意味着您可以使用 .NET 4.0 程序集。不支持。

标签: .net visual-studio-2010 windows-phone-7


【解决方案1】:

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
  • 系统.* - 2.0.5.0

【讨论】:

  • 您很可能添加了对 XNA 框架的 PC 版本的引用,而不是电话版本。您需要发布您的 .csproj 文件,以获得更详细的帮助。
  • 另外,您的参考资料并未列为受支持的 Phone 7 平台(例如:msdn.microsoft.com/en-us/library/…
【解决方案2】:

Windows Phone 使用 Silverlight(Silverlight 3 for 7.0,Silverlight 4 for Mango),它没有运行完整的 .NET CLR,而是使用完整 .NET CLR 的子集(请参阅 Silverlight on Windows Phone、@987654322 上的 MSDN 链接@)。因此,您无法引入 .NET 4.0 程序集甚至完整的 .NET 2.0 程序集。

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

不过,这意味着您可以将一些 Silverlight 程序集添加到 Windows Phone 中(例如,这就是您为 Silverlight 单元测试框架所做的)。如果您这样做,则会收到一条警告,即并非所有桌面 Silverlight 在 Windows Phone 中都受支持。你应该小心地这样做,因为事情可能会破裂......

【讨论】:

    【解决方案3】:

    请检查您使用的是 .NET Framework 还是 .NET Framework 客户端配置文件。如果是客户端配置文件,请将其更改回 .NET Framework。

    【讨论】:

    • Phone 7 项目没有这样的东西
    猜你喜欢
    • 1970-01-01
    • 2011-02-09
    • 2011-06-30
    • 2011-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-02
    相关资源
    最近更新 更多