Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

NCrunch and GitVersion
Tim Long
#1 Posted : Friday, June 21, 2019 6:48:58 PM(UTC)
Rank: Member

Groups: Registered
Joined: 8/20/2016(UTC)
Posts: 14
Location: United Kingdom

Was thanked: 1 time(s) in 1 post(s)
I'm using GitVersion to automatically version my code. Specifically, I use the GitVersionTask NuGet package that installs an MSBuild task to extract the version information during every build. One of the things this task does is to "inject" a static class called GitVersionInformation. I access this in my code for things like displaying the version string in the About box and emitting version strings to the log file. In fact, the first thing my code does is write out some version strings using NLog:

Code:

        [STAThread]
        private static void Main(string[] args)
            {
            // Manage unhandled exceptions
            Application.ThreadException += UnhandledThreadException;
            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Log.Info("Git Commit ID: {fullCommit}", GitVersionInformation.Sha);
            Log.Info("Git Short ID: {shortCommit}", GitVersionInformation.ShortSha);
            Log.Info("Commit Date: {commitDate}", GitVersionInformation.CommitDate);
            Log.Info("Semantic version: {semVer}", GitVersionInformation.SemVer);
            Log.Info("Full Semantic version: {fullSemVer}", GitVersionInformation.FullSemVer);
            Log.Info("Build metadata: {buildMetadata}", GitVersionInformation.FullBuildMetaData);
            Log.Info("Informational Version: {informationalVersion}", GitVersionInformation.InformationalVersion);
            // [other stuff elided for clarity]
            }


Visual Studio is happy with this, and the code builds without issues - but not in NCrunch. In NCrunch, I get this:

Quote:

LocalServer.cs (99, 53): 'GitVersionInformation' is inaccessible due to its protection level
LocalServer.cs (100, 53): 'GitVersionInformation' is inaccessible due to its protection level
LocalServer.cs (101, 51): 'GitVersionInformation' is inaccessible due to its protection level
LocalServer.cs (102, 52): 'GitVersionInformation' is inaccessible due to its protection level
LocalServer.cs (103, 61): 'GitVersionInformation' is inaccessible due to its protection level
LocalServer.cs (104, 57): 'GitVersionInformation' is inaccessible due to its protection level
LocalServer.cs (105, 71): 'GitVersionInformation' is inaccessible due to its protection level


Protection level? Probably not correct. It's a static internal class and Visual Studio is perfectly happy to compile that code. I guess there's some subtlety I'm not seeing about the MSBuild task. Any advice?

Thanks,
Tim
Remco
#2 Posted : Friday, June 21, 2019 10:23:09 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,818

Thanks: 752 times
Was thanked: 972 time(s) in 926 post(s)
Hi Tim,

Thanks for sharing this issue.

Does setting your 'Instrument Output Assembly' setting to 'False' for the assemblies involved make any difference here?

Are you making use of InternalsVisibleToAttribute anywhere in your code?
Der-Albert.com
#3 Posted : Thursday, June 27, 2019 3:44:52 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/17/2011(UTC)
Posts: 173

Thanks: 8 times
Was thanked: 37 time(s) in 34 post(s)
You can fix this with with disabling everything GitVersion related in your Project File.



Code:
  <PropertyGroup Condition="'$(NCrunch)' == '1'">
    <WriteVersionInfoToBuildLog>false</WriteVersionInfoToBuildLog>
    <UpdateAssemblyInfo>false</UpdateAssemblyInfo>
    <GenerateGitVersionInformation>false</GenerateGitVersionInformation>
    <GetVersion>false</GetVersion>
    <GenerateGitVersionWixDefines>false</GenerateGitVersionWixDefines>
    <UpdateVersionProperties>false</UpdateVersionProperties>
  </PropertyGroup>


I opened an issue on GitHub for GitVersion.Task https://github.com/GitTools/GitVersion/issues/1723
1 user thanked Der-Albert.com for this useful post.
Remco on 6/27/2019(UTC)
Der-Albert.com
#4 Posted : Friday, July 12, 2019 5:32:50 PM(UTC)
Rank: Advanced Member

Groups: Registered
Joined: 5/17/2011(UTC)
Posts: 173

Thanks: 8 times
Was thanked: 37 time(s) in 34 post(s)
Since Version 5.0.0-beta5 you can use

Code:

  <PropertyGroup Condition="'$(NCrunch)' == '1'">
    <DisableGitVersionTask>true</DisableGitVersionTask>
  </PropertyGroup>


in the project file to disable the gitversiontask if needed.
henning-moe
#5 Posted : Monday, October 7, 2019 12:51:18 PM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/26/2019(UTC)
Posts: 2
Location: Norway

I can't get this to work...

I'm using this:
Code:
<PropertyGroup Condition="'$(NCrunch)' == '1'">
    <DisableGitVersionTask>true</DisableGitVersionTask>
</PropertyGroup>


It's a .NET Standard 2.0 dll using the new project format (or actually, several) and none of them work in NCrunch. It's as if $(NCrunch) isn't defined in the build. If I set it unconditionally it works but that's no good.
Remco
#6 Posted : Monday, October 7, 2019 11:02:51 PM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,818

Thanks: 752 times
Was thanked: 972 time(s) in 926 post(s)
Could you try specifying this value using the Custom Build Properties configuration setting?
henning-moe
#7 Posted : Wednesday, October 9, 2019 8:39:25 AM(UTC)
Rank: Newbie

Groups: Registered
Joined: 3/26/2019(UTC)
Posts: 2
Location: Norway

Remco;13929 wrote:
Could you try specifying this value using the Custom Build Properties configuration setting?


I tried to set NCrunch=1 in Custom build properties but that didn't work. I tried to add IsNCrunch = true and use that instead but that didn't work.

What *did work* however was to set DisableGitVersionTask = true in custom build properties. I'm not clear on what the difference is effectively.

Edit: that's a better solution anyway as I check in NCrunch settings anyway.
Remco
#8 Posted : Wednesday, October 9, 2019 8:58:48 AM(UTC)
Rank: NCrunch Developer

Groups: Administrators
Joined: 4/16/2011(UTC)
Posts: 5,818

Thanks: 752 times
Was thanked: 972 time(s) in 926 post(s)
Remco;13929 wrote:

What *did work* however was to set DisableGitVersionTask = true in custom build properties. I'm not clear on what the difference is effectively.


Sorry, I should have been more specific ... this was what I was trying to suggest doing :)

It's a bit concerning that the NCrunch environment variable isn't available in your build conditions. Something must be blocking this from your build system. Regardless, the Custom Build Properties can be used for overriding anything of this sort, and is probably a cleaner option.
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

YAF | YAF © 2003-2011, Yet Another Forum.NET
This page was generated in 0.051 seconds.