private bool ShowRetargetingDialog()
{
var retargetDialog = this.site.GetService(typeof(SVsFrameworkRetargetingDlg)) as IVsFrameworkRetargetingDlg;
if (retargetDialog == null)
{
throw new InvalidOperationException("Missing SVsFrameworkRetargetingDlg service.");
}
// We can only display the retargeting dialog if the IDE is not in command-line mode.
if (IsIdeInCommandLineMode)
{
string message = SR.GetString(SR.CannotLoadUnknownTargetFrameworkProject, this.FileName, this.TargetFrameworkMoniker);
var outputWindow = this.site.GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
if (outputWindow != null)
{
IVsOutputWindowPane outputPane;
Guid outputPaneGuid = VSConstants.GUID_BuildOutputWindowPane;
if (outputWindow.GetPane(ref outputPaneGuid, out outputPane) >= 0 && outputPane != null)
{
Marshal.ThrowExceptionForHR(outputPane.OutputString(message));
}
}
throw new InvalidOperationException(message);
}
else
{
uint outcome;
int dontShowAgain;
Marshal.ThrowExceptionForHR(retargetDialog.ShowFrameworkRetargetingDlg(
this.Package.ProductUserContext,
this.FileName,
this.TargetFrameworkMoniker.FullName,
(uint)__FRD_FLAGS.FRDF_DEFAULT,
out outcome,
out dontShowAgain));
switch ((__FRD_OUTCOME)outcome)
{
case __FRD_OUTCOME.FRDO_GOTO_DOWNLOAD_SITE:
Marshal.ThrowExceptionForHR(retargetDialog.NavigateToFrameworkDownloadUrl());
return false;
case __FRD_OUTCOME.FRDO_LEAVE_UNLOADED:
return false;
case __FRD_OUTCOME.FRDO_RETARGET_TO_40:
// If we are retargeting to 4.0, then set the flag to set the appropriate Target Framework.
// This will dirty the project file, so we check it out of source control now -- so that
// the user can associate getting the checkout prompt with the "No Framework" dialog.
if (QueryEditProjectFile(false /* bSuppressUI */))
{
var retargetingService = this.site.GetService(typeof(SVsTrackProjectRetargeting)) as IVsTrackProjectRetargeting;
if (retargetingService != null)
{
// We surround our batch retargeting request with begin/end because in individual project load
// scenarios the solution load context hasn't done it for us.
Marshal.ThrowExceptionForHR(retargetingService.BeginRetargetingBatch());
Marshal.ThrowExceptionForHR(retargetingService.BatchRetargetProject(this, DefaultTargetFrameworkMoniker.FullName, true));
Marshal.ThrowExceptionForHR(retargetingService.EndRetargetingBatch());
}
else
{
// Just setting the moniker to null will allow the default framework (.NETFX 4.0) to assert itself.
this.TargetFrameworkMoniker = null;
}
return true;
}
else
{
return false;
}
default:
throw new ArgumentException("Unexpected outcome from retargeting dialog.");
}
}
}