开发者

Add custom version information to C# application

开发者 https://www.devze.com 2023-01-28 12:55 出处:网络
Application is a C# 开发者_Python百科.Net 3.5 WCF Service. I\'d like during the build process to dynamically add some build information to the final binary and assemblies that can then be read progra

Application is a C# 开发者_Python百科.Net 3.5 WCF Service.

I'd like during the build process to dynamically add some build information to the final binary and assemblies that can then be read programatically and sent back to the WCF client when it sends a GetVersionInfo request to the web service.

.Net assembly versioning isn't enough. I want to include additional string data that contains the state of the system at the time the application was built.

I'm thinking that I'd do this by adding a post build event to call a script to update the app.config file with the data I want. Does this sound about right, or should I be considering some other approach?

Update

I'd additionally like this string to appear in the "Special Build Description" property of the final exe. I.e. I'd like to right click on the file and see this information in the version tab for the file.

Thanks in advance.


I suspect a pre-build event may be more appropriate than post-build... have you considered adding a buildinfo.xml file (or similar) to be built into the assembly as an embedded resource? You could then load it with Assembly.GetManifestResourceStream. That way you don't need to worry about fitting in with existing files or anything like that - just overwrite buildinfo.xml with a new file in the pre-build step.


You have to decide how important it is that the information you want to exchange is tied to the executable file itself.

Updating the config file during the built is a workable model, but it places the information in a location where it could be altered by anyone with access and a text editor.

Updating information after a build in a compiled assembly is certainly possible, but it's fragile and breaks down if you ever decide to sign the assemblies. It's also a lot of work, since there's no built it support for re-writing assembly files in this manner.

An alternative you should consider, is creating your own custom assembly-level metadata attributes and assigning them during the build process. You could even place them in a separate code file (or append them to AssemblyInfo.cs) as part of you build.

You could also consider creating an embedded resource (an XML file, for instance), and retrieving it from the assembly manifest at runtime.

Either of the above approaches would require you to use a pre-build custom step rather than a post-build step.

Personally, I find the metadata attributes a convenient approach if there isn't a lot of data. Otherwise, I would consider using an embedded resource file.

0

精彩评论

暂无评论...
验证码 换一张
取 消