How to retrieve OutputAssemblyInfo for Project that does not compile?

By some experimentation I found that I can retrieve assembly information from an IProject using the GetOutputAssemblyInfo() extension method. While this is nice, it does not seem to work when the respective project does not currently compile. It turns out that the OutputAssemblyInfo property of the ProjectImpl instance, i.e., the IProject instance, is null. I understand that in case of uncompilable code there is no output assembly and, therefore, no information about it. However, the information (like the name and version) are part of the project properties and, thus, available anyways. I don't seem to be able to retrieve these information from anywhere within the IProject instance. Am I blind or am I looking the wrong way?

Best,
Sven

5 comments
Comment actions Permalink

I'm not aware of it becoming null. I'll look into it. In the meantime, what information are you after? If it's the output path, you can use IProject.GetOutputFilePath() for that, and it won't be null (it's got the [NotNull] annotation on it)

0
Comment actions Permalink

I'm after the assembly version.

Thanks.

0
Comment actions Permalink

As far as I can see, the OutputAssemblyInfo property is only set once there is a successfully built assembly. It appears to get the info from the assembly itself, rather than the source - it has the MVID which is a guid the compiler embeds in the assembly, so it must be using the physical assembly. If you haven't yet built the project at all, or if you've just done a clean, then the OutputAssemblyInfo is going to be null. Once you have a successful build, the OutputAssemblyInfo will be valid, until you do a clean, and will be updated when you build again. It does not get set to null when the code can't compile (unless your compile process also does a clean).

If you need the version number, you can either get it from the OutputAssemblyInfo when it's valid, and use 0.0.0.0 otherwise, or you can try and parse out the AssemblyVersionAttribute in AssemblyInfo.cs. The downside to this method is that AssemblyVersionAttribute might not always be in AssemblyInfo.cs, and sometimes, it will be something like "1.0.*", which produces a new version number on each build (it's based on the current time, I think, but I'm not sure how it's calculated).

Hope this helps
Matt

0
Comment actions Permalink

It also seems to be null if I start VisualStudio with the project in an uncompilable state. But I'm not entirely sure whether there is some cleanup performed in the course of restarting. But if it's kept (at least for the IDE session) after one successfull build, I know that I don't need to build up a manual cache for the same purpose. I think I'll just except my fate here. Should not happen too often (I hope xD).

Thanks for the clarification!
Best,
Sven

0
Comment actions Permalink

EDIT: Sorry! Wrong thread...


0

Please sign in to leave a comment.