Change the ProductName, version, revision by code

Noah Aas 985 Reputation points
2024-10-22T14:39:58.9033333+00:00

Hello,

Assembly thisAssem = typeof(TestVersion).Assembly;
AssemblyName thisAssemName = thisAssem.GetName();

Version ver = thisAssemName.Version;

thisAssemName.Name = thisAssemName.Name + ", " + revision;

Console.WriteLine("This is version {0} of {1}.", ver, thisAssemName.Name);

I would like to give my test DLL its own revision. Is it possible to do this via the code?

Or only via Reflection Assembly?

Developer technologies | C#
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2024-10-23T01:45:48.6166667+00:00

    Hi @Noah Aas , Welcome to Microsoft Q&A,

    The assembly's version information (AssemblyVersion, 'AssemblyFileAssemblyFileVersion, etc.) is set at compile time via 'AssemblyInfo.csAssemblyInfo.cs or .csproj files and embedded in the DLL or EXE file. This information is part of the assembly's metadata and is static and can only be set at compile time. Therefore, you cannot dynamically change the revision for a test DLL directly through code. This information is read-only and reflection can only read but not modify it.

    You can set them in 'AssemblyInfo.cs.

    [assembly: AssemblyVersion("1.0.0.*")]
    [assembly: AssemblyFileVersion("1.0.0.1234")]
    [assembly: AssemblyProduct("YourProductName")]
    

    Best Regards,

    Jiale


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment". 

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.