question

JhonasBoeno-2573 avatar image
0 Votes"
JhonasBoeno-2573 asked PengGe-MSFT commented

How to generate random AssemblyName each build?

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?


dotnet-csharpvs-msbuild
vs.png (74.2 KiB)
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi, @JhonasBoeno-2573
I found this thread that may help you.


0 Votes 0 ·

0 Answers