This project has moved and is read-only. For the latest updates, please go here.

Error in .NET-package install using NuGet and PTVS 2.0


I am trying to create a MahApps styled WPF application using IronPython 2.7.3 in Visual Studio Ultimate 2012 with PTVS 2.0. However I cannot install MahApps.Metro via Nuget using the GUI. Choosing 'Install' in the Manage NuGet Packages console trows the following error by Visual Studio:

'MahApps.Metro' could not be installed because it is not compatible with any project in the solution. The package targets the following frameworks:

.NetFramwork, Verion=v4.0

.NetFramwork, Verion=v4.5

Trying out different .NET packages trough the NuGet Manager all trough the same errors.

I have created a new IronPython WPF application using both the .NET 4.0 and 4.5 Framework.

Any suggestions into how I could install mahapps.metro assemblies in an IronPython WPF application either using NuGet or an alternative way would be greatly appreciated.

(FYI: I made a C# WPF application using the same frameworks. Here I can install the MahApss assemblies as I should and they work perfectly fine there.)


Zooba wrote May 23, 2013 at 4:29 PM

Unfortunately, when the core VS teams add a feature like this they don't work with us on it, so we usually have to catch up later.

I haven't tried, but this may be as easy as setting a property in the .pyproj file (for example, we probably don't set the target .NET framework version, even though you can select it in the New Project dialog).

You could open the .pyproj and .csproj files in a text editor and compare them - they're just XML files. We won't be exposing the property in the UI anywhere, so this is the only option. Editing project files is pretty safe though.

If you find a way to make it work let us know so we can tell other people and make any changes to our templates. (If you don't find a way then we'll have to triage this feature against all the rest - it probably won't make 2.0 final.)

JandalDoe wrote May 25, 2013 at 12:59 PM

Thank you for the reply Zooba I have found an alternative solution to this problem.

First I have tried your suggestion, yet unfortunately with no result. The project file generated from a IronPython WPF application *.pyproj structure does miss a reference to the .NET Framework wheras a the project file from a C# WPF application does not:
<?xml version...
<Project ToolsV...
    <Import Pro...
However adding this reference to the *.pyproj file did nothing for the NuGet installation error.

Manually adding packages without using NuGet for IronPython (WPF) applications (work-around)

So next I looked for an alternative way of installing the package without having to use NuGet at all:
  1. Install the NuGet package in a C# WPF project as per the instructions. For Mahapps:
  2. Next create a new IronPython WPF Application
  3. If you explore both projects in the explorer the C# project will have a folder in the solution folder of the project called 'packages' this folder contains the just installed NuGet packages and their .dll's. Copy this folder to the solution folder of the python project.
  4. Now you are able to reference the .dll's from the package (NuGet would normally do this automatically for you)
    In case of referencing MahApps set references to: MahApps.dll and System.Windows.Interactivity.dll in
  5. Don't forget to set the search path to the same path in your project. (for clr.AddReference() to be able to find the assemblies)
  6. Now you can import the assemblies from the package in your IronPython script:
import wpf
import System.Windows
from System.Windows import Application

import clr
import MahApps.Metro.Controls
from MahApps.Metro.Controls import MetroWindow
  1. You can now follow the installation strategy on The result will look something like this:
In the IronPython script
import wpf
import System.Windows
from System.Windows import Application

import clr
import MahApps.Metro.Controls
from MahApps.Metro.Controls import MetroWindow

import System.Windows.Interactivity

class MainWindow(MetroWindow):
    def __init__(self):
        wpf.LoadComponent(self, 'IPython_WPF.xaml')

if __name__ == '__main__':
In the YourWindow.xaml script
       Title="IPython_WPF" Height="300" Width="300"> 
It's quite the elaborate work-around but it works! I guess it would be interesting if someone would able to find out why exactly the NuGet installation doesn't detect the proper .NET framework for IronPython scripts. I am pretty sure you are not able to change anything in your templates to automate this process (I have tried to install all .NET 4.0 assemblies in the IronPython WPF application that are automatically present in the C# WPF application on start up but also then NuGet trows the same error).

I guess for the time being this work-around should suffice.

Zooba wrote May 25, 2013 at 4:54 PM

Thanks for the great write up!

If you're really keen to figure out how NuGet is validating the project you can actually look at their source code: This is all we'll be doing (eventually... which is why you may want to do it sooner :) )