Force Target Framework

Jun 27, 2011 at 4:32 PM

What is the correct way to force a project to a target framework?  I realize one can ship assemblies targetted against different frameworks(net40, net35, sl4, etc.), but is there a way to force the framework.

I have an assembly that requires the .NET Framework 4 Full, not theclient profile.  (The assembly depends on System.Workflow.Runtime.) I created a NuGet package, and placed the assembly in lib/net40-Full. The assembly is installed even though the project has .NET Framework 4 Client Profile as the Target Framework.  (I would have expected it to complain, and not install.)

I tried to solve the problem using install.ps1. 
>> install.ps1 <<


param($installPath, $toolsPath, $package, $project)

$name = $project.Name;
$requiredFrameworkMoniker = ".NETFramework,Version=v4.0";
$frameworkMoniker = $project.Properties.Item("TargetFrameworkMoniker").Value

if ($frameworkMoniker -ne $requiredFrameworkMoniker) {    
    write-host "Setting Target Frameworkt to .NET 4.0 ...
    $frameworkMoniker = $project.Properties.Item("TargetFrameworkMoniker").Value = $requiredFrameworkMoniker;


This solution kind of works.  The assembly is installed, and theTarget Framwork is set appropriately. But, the following error messageis displayed.

    Install failed. Rolling back...

Despite this error message, the assembly is left installed.

I tried a fancier solution whereby I wrapped the setting of $frameworkMoniker in a try/catch, and explicitly waited for the project to be reloaded. This did not work.  I don't want users to see the benign error message, and I am concerned about this message myself.

Thoughts?  Is this even possible, or am I not doing this the right way?

Jun 27, 2011 at 5:46 PM

It's just wrong to change the project's target framework to suit your package. I believe the reason we let things install into the client profile even if there's only a full was the fact that we didn

t want to make a breaking change but that might have been the wrong decision.

Jun 27, 2011 at 6:03 PM

In some ways I agree with, but how does one solve the problem?

The assembly requirement (System.Workflow.Runtime) dictates the Framework version.  Setting the user up for failures seems worse IMHO.  The package manager should ensure the dependencies are satisfied or else fail appropriately.  An error message would work for me.  Would you like me to open a bug to revisit this decision?

Is it that major of an impact to the user to convert him from Client Profile to Full?  Honestly, I do not know.  I only know my _small_ world, and my gut reaction is no.

Jun 27, 2011 at 6:09 PM

Yes I'm saying we open a bug and should revisit the decision. You're package isn't the only package the user might be installing and I don't think a package should dictate what a project targets, that's the project owners decision. If the package requires a framework that I'm not targeting it should fail.

Jun 27, 2011 at 6:21 PM
Edited Jun 27, 2011 at 6:23 PM

Thank-you for your consideration!

I have opened issue 1240.