How to change the Assembly Name in C# Programmatically

眉间皱痕 提交于 2019-12-05 22:28:30

问题


I want to change the name of my Assembly Programmatically in C#, there is a way through which I can change it from Project Properties, but I want to change it Programmatically, so that my output .exe name is changed.. Any trick for that?


回答1:


You could do this in the Post-Build Event. These scripts are commandline scripts that get executed after the Build process finished

ren "$(TargetFileName)" new-filename.exe

Edit:

You can configure the Postbuild Event by right-clicking on your Project in Visual Studio and selecting Properties. There you have a Tab called Buildevents. There is one for Prebuild and one for Postbuild. At the bottom you can select under what circumstances the Script should be run. This description assumes you are using Visual Studio 2008. The Events are also available in earlier versions, and the way to reach them should be similar (sorry, can't remember exactly howto).

Note: if the assembly file name has space then insert $(TargetFileName) between two quotation, like this: "$(TargetFileName)"




回答2:


In a post-build event, this should do the trick:

if <Condition> == <truevalue> xcopy output.dll newassembly.dll /y /s /d

To configure post-build events: right-click the project in Solution Explorer, click Properties, then click Build Events.



来源:https://stackoverflow.com/questions/1425323/how-to-change-the-assembly-name-in-c-sharp-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!