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,692

Thanks: 738 times
Was thanked: 944 time(s) in 899 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: 162

Thanks: 7 times
Was thanked: 34 time(s) in 32 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: 162

Thanks: 7 times
Was thanked: 34 time(s) in 32 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.
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.040 seconds.