How to generate random AssemblyName each build?

Jhonas Boeno 1 Reputation point
2021-10-30T04:46:23.527+00:00

Hi. I'm developing an addon for a Unity-based game. The addon is written in C#, class library. Since the game takes some time to launch, I'm trying to reload my DLL at runtime, doing this will help me save time by not having to wait for the loading screen. I've already got a similar result using AppDomains but I found that some methods were throwing exceptions and the cause is communication between AppDomains. It seems like to use AppDomains the classes need to be serializable or inherit from a certain class, but I don't have access to the game's source code, so I can't change some things. So I am trying to reload an assembly in the same AppDomain, but changing its name, as it is not possible to reload another assembly in the same AppDomain if another one is already loaded. The problem is I can't generate random assembly name each build. See below what I tried to do:

In my .csproj, I included these three lines of code:

<PropertyGroup>  
  <MyNewGuid>$([System.DateTime]::Now.ToString("HHmmss"))</MyNewGuid>  
</PropertyGroup>  

And in the AssemblyName property I put something like this:

<AssemblyName>MyFirstMod$(MyNewGuid)</AssemblyName>  

As you can see, it will include the current time in the assembly name, but sometimes when I click to build the solution, it includes an old time. Looks like Visual Studio is caching and not running the code in the MyNewGuid property every time.

145100-vs.png

How can I generate random assembly name every build every time?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,249 questions
Not Monitored
Not Monitored
Tag not monitored by Microsoft.
36,001 questions
{count} votes