Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Visual Studio 2010 use .NET 4.0 instead of .NET 2.0 on a Windows Phone project?

This is a Windows Phone 7 project.

For some strange reason, Visual Studio 2010 will not let me set the target .NET version to .NET 4.0 in the project settings, Application tab. It's grayed out.

When I compile the project, the XNA assemblies are .NET 4.0, but System and System.Core and all the rest are .NET 2.0.

When I say "Add Reference", it won't let me select any of .NET 4.0 system assemblies like mscorlib.

I uninstalled .NET 4.0 and then reinstalled it. No help.

Edit: My ultimate goal is to get this to compile. Why is it choosing .NET 2.0 for the System assemblies?

Edit: I'm getting these errors:

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

Edit: OK, I removed those offending XNA assemblies. It turned out that I didn't need them. Now the compiler is back to this error:

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

Compile complete -- 1 errors, 0 warnings
like image 484
101010 Avatar asked Jan 22 '26 09:01

101010


2 Answers

Visual Studio is showing you the correct assemblies. You cannot select .NET 4.0 assemblies for Windows Phone 7 for the simple reason that Windows Phone 7 doesn't run .NET 4.0.

The versions you see should be like this:

  • Microsoft.Phone.* - 7.0.0.0
  • Microsoft.XNA.* - 4.0.0.0
  • mscorelib - 2.0.5.0
  • System.* - 2.0.5.0
like image 175
Claus Jørgensen Avatar answered Jan 25 '26 20:01

Claus Jørgensen


Windows Phone uses Silverlight (Silverlight 3 for 7.0, Silverlight 4 for Mango) which isn't running the full .NET CLR, but uses a subset of the full .NET CLR (see MSDN links on Silverlight on Windows Phone, Silverlight Architecture). Therefore you can't pull in .NET 4.0 assemblies or even full .NET 2.0 assemblies.

The 2.0.5.0 version numbers you can see are special Silverlight version numbers - these aren't actually full .NET 2.0 assemblies.

However this means you can add some Silverlight assemblies into Windows Phone (this is what you do for Silverlight Unit Test framework for instance). If you do this then you get a warning that not all of desktop Silverlight is supported in Windows Phone. You only should do this with care as things may break...

like image 22
Paul Annetts Avatar answered Jan 25 '26 18:01

Paul Annetts



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!