How to reload a new build without restarting Revit

i am going thru tutorials on writing Grasshopper components in VisualStudio 2019.
I am using Revit 2020 and RIR v1.2.7955.32919 (10/12/2021 18:17:18).

When i make changes to my code and get a new build, it fails to copy the DLL file to its proper location as it is in use.
i tried closing Grasshopper window, and i also tried exiting the RIR but neither will let me overwrite the DLL.
The only way i could get it to work is by exiting Revit, redo the build, then restart Revit.

That is extremely cumbersome and wastes a lot of time.
Is there any other way to reload the DLL without exiting anything?

Hi @fawzi,

I use all the time the Apply Code Changes on Visual Studio.
It works pretty well for minor changes, give it a try it will save you a lot of time.

I think is available since

Microsoft Visual Studio 2019
Version 16.11

Visual Studio 2019 version 16.11 Release Notes

i am not able to find that button, from the image you provided. How do i get to it?
i am using Version 16.11.5


ok, so i found it… It is the fire icon. (or Alt-F10)

i did like it, but i am looking for more. the “Apply Code Changes” seems to be for final stage of fine tuning the code. It is only available when you are in debug mode, i.e. the application is running.

i tested it briefly and it worked for adding a variable, or assigning different values to existing variables.

However, i could not use it with changing/adding new parameters to a functions. when i do that, it requires i stop the debugger. So i am still at the onset of writing this function and i would be adding parameters, etc…

Revit Add-Ins are loaded in the primary .NET AppDomain, on the same domain RevitAPI itself is loaded, and unloading .NET assemblies is not possible while the AppDomain is up and running.

See How to: Load and unload assemblies | Microsoft Docs

About “Apply Code Changes”, it allows you to introduce new types or even new methods in existing types.

When I’m in this situation I just add a new method called same name but with the new parameter I like to add.
The only thing you need to keep is the old method declaration line, but the body maybe just a => default;.

// Old Code
public Brep[] CreateSolidSkipNulls(IEnumerable<Brep> breps)
    return Brep.CreateSolid(brep.Where(x => x is Brep), 0.001);
// New Code
// TODO: Delete this method, it was a prototype
public Brep[] CreateSolidSkipNulls(IEnumerable<Brep> breps) => default;
public Brep[] CreateSolidSkipNulls(IEnumerable<Brep> breps, double tolerance)
    return Brep.CreateSolid(brep.Where(x => x is Brep), tolerance);

I see, so it is like overloading (i think that is the correct naming) your function.

i am sure i will use that trick.

I am not sure if this is related. but in this post, Joshua Lumley goes through how to write macros without having to restart Revit every time you make a change. And i have been using it with my macro. i am just not savvy enough to extend it to here for grasshopper nodes.