by Guy Robinson
31. May 2010 14:04
For those of you excited by .NET4.0’s new features and wanting to test Revit commands compiled with .NET4.0, you’re in luck. Before I show you how, a few caveats:
- I’ve tested this for a few days. While I haven’t run into any unexplained issues , there are areas of new functionality in .NET4 that can cause a bit of a head scratch.
- Of course this is unsupported so you can try submitting a bug but don’t be surprised if Autodesk just laugh at you. In other words, “testing and inhouse development only please”.
How to enable .NET4.0
Assuming you have .NET4.0 installed, to enable .NET4.0 support change the runtime lines in the Revit.exe.config to the following. Note if this isn’t the .NET2 version installed then you need to modify the .NET2 version as required.
<startup useLegacyV2RuntimeActivationPolicy="true" >
<supportedRuntime version="v4.0"/>
<supportedRuntime version="v2.0.50727" />
</startup>
The critical line is the useLegacyV2RuntimeActivationPolicy=true. To confirm this is working, create a .NET4 assembly and add the following command.
[Transaction(TransactionMode.Manual)]
[Regeneration(RegenerationOption.Manual)]
[DisplayName("Test NET40")][Description("Test NET4.0 test command")]public class Command:IExternalCommand
{ #region Implementation of IExternalCommand
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{ var uiApplication = commandData.Application;
var application = uiApplication.Application;
var uiDocument = uiApplication.ActiveUIDocument;
var document = uiDocument.Document;
var transaction = new Transaction(document, "test .NET4.0");
try
{ transaction.Start();
var td = new TaskDialog("Test Version4") { MainContent = "Running CLR " + Environment.Version.ToString() }; td.Show();
transaction.Commit();
return Result.Succeeded;
}
catch (Exception)
{ if (transaction.HasStarted()) transaction.RollBack();
return Result.Failed;
}
}
#endregion
}
Enjoy!!! Looking forward to seeing some Revit->Windows Phone7 mashups!!
Just to clarify, although you can test .NET4 commands Revit is unusable with .NET4 enabled. It causes Revit to crash as soon as you select a standard command.