-
Notifications
You must be signed in to change notification settings - Fork 654
Modified the VB.NET Template so that GitVersionInformation is in the Global namespace #2313
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
asbjornu
merged 2 commits into
GitTools:master
from
odalet:feature/put-vbnet-code_in-global-namespace
Jun 14, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just thinking, if
GitversionInformation
is moved to the global namespace, won't this make ILMerging difficult? If several of the merged assemblies are versioned with GitVersion, we would potentially end up with several collidingGitversionInformation
classes?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That poses no problem because the generated classes are, and this is very important, internal. An external assembly cannot see these class unless you use reflection, and when using reflection they are resolved with their full name (which happens to be only the class name) against a specific assembly, therefore, no collision.
This trick, I often use with Visual Studio's "shared projects": they are just bunches of code that get "included" into the consuming project. I always make sure classes in these shared projects are internal so that they can be used from any assembly even if these assemblies reference one another.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if this were an issue, it would already have shown with C# or F# generated classes that are already part of the global namespace (and internal).
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mmmh, maybe I spoke too quickly, I missed the bit about ILMerge... Everything being part of the same assembly in the end, it may be an issue. I'll give it a try, and sorry if you thought I was teaching you how visibility worked in .NET! However, my point that the issue already exists if any is still valid.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, after a quick googling, it appears this indeeds poses problems:
See https://stackoverflow.com/a/14042227/107552
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And with Fody + Costura, everything just works out of the box. This is because, the principle is radically different. The assembies' IL is not merged, instead the dependent assemblies are embedded as resources in the main assembly, then extracted and loaded at runtime (during module initialization). Thus, the assemblies never cease to exist as such and type resolution just works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you are interested in witnessing the tests I did, everything is in this repository: https://github.com/odalet/GitVersionTests
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And now for ideas on how this whole "code generation" thing could be tweaked:
The generated class could be put in a namespace or have a name that will guarantee non-collision. To guarantee this, the class name should be based on the assembly name (and not on some 'default' or root namespace). The class could be inside a namespace named as the assembly or be an inner class inside a class named like the assembly or be a concatenation of assembly name and
GitVersionInformation
...A property / command line argument could be provided to let the user choose the name of the generated class.
I recently stumbled upon the GitInfo. Its purpose is similar to GitVersion's with the following differences:
It, too, generates code containing version information. However:
For example, here is what I can write when using GitInfo:
The advantage of this strategy is that because constants are inlined in the calling code, the original type that exposes them is useless at runtime and therefore, collisions on this type are not anymore an issue. And being able to use the version information without reflection also seems more user-friendly.
So, mixing some of these ideas may be the way to go. However, in any case, it is quite some work, and most probably breaking. In the meantime, my experiments with a selection of assembly merging tools show that the collision problem can be mitigated.
It's now up to you to reflect upon all this and decide what or what not to do :)
Hope this helped!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Constants are a great idea for how we can implement this in a new major version of GitVersion! Whether we'll do this for v6 or not is mainly dependent on timing; if someone submits a pull request implementing this before we go live with v6, it will be released with v6. If not, we would have to postpone it to v7.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generating constants should be rather straightforward. The MSBuild part that generates this soon so that the user can call into it may be a little trickier (I'm not very proficient at MSBuild ;)).
I'll probably come up with an issue that will serve as a discussion and specification of what can be done.