Skip to content

added option to disable gitversiontask on build #1724

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

Closed
wants to merge 5 commits into from
Closed

added option to disable gitversiontask on build #1724

wants to merge 5 commits into from

Conversation

DerAlbertCom
Copy link

@DerAlbertCom DerAlbertCom commented Jun 27, 2019

@DerAlbertCom
Copy link
Author

i have no idea how to test this in the test project. I found no clue about testing setting build properties. i tried even to break the tests, with setting some properties in the .props file to random values, seems not be used at all 😄

@arturcic
Copy link
Member

You can run the project using http://msbuildlog.com/ and see the props and the targets that are used

@DerAlbertCom
Copy link
Author

Didn't know that tool, but seems I'm not worthy ;) Also, i'm not familiar with creating Build Targets.

I've run msbuild /bl on the GitVersionTask, GitVersionTask.Test and the complete solution, viewed the logfiles, and found zero evidence that any properties of the .props file is set.

the build.ps1 is stopping on Pack-Gem because i don't have ruby, this can i comment out, but it is failing on other stuff. But this all only for one manual test. This is not a good idea.

Currently i'm trying running msbuild in memory in the unit, that works, but have problems with adding the build targets. will check this out a little bit further.

Or any other Ideas?

@arturcic
Copy link
Member

I used that tool when I tested the changes I did when updated to Libgi2sharp 0.26.0. It's really easy to use it.

@DerAlbertCom
Copy link
Author

I'm not against that tool, i search for the properties in the log, nothing found. i have to create a test project which includes the nuget package. and it is still a manual test.

So i decided to give a unit test a try, so this is currently building. if the build now succeeds (worked with dotnet test, but not with nunit in the build script) I rebase that stuff.

@arturcic arturcic self-requested a review June 28, 2019 07:54
@arturcic
Copy link
Member

@DerAlbertCom I like the idea of how you tested the properties, I guess we might be using this approach for testing the tasks by running the msbuild the same way. These way we can cover the msbuild tasks as well. I gave a try the test locally with Visual studio test adapter as well as Resharper and the Unit test were failing on my machine. I can see they are also failing on the appveyor.

I would suggest to make some small changes to the code so that the tests can run everywhere (VS + resharper)

(bool failed, Project project) CallMsBuild(IDictionary<string, string> globalProperties)
        {
            var currentDirectory = AppDomain.CurrentDomain.BaseDirectory;
            var projectXml =
                $@"<Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
<PropertyGroup>
            <TargetFramework>net461</TargetFramework>
            <Configuration>Debug</Configuration>
            <GitVersionTaskRoot>{currentDirectory}\..\..\..\..\GitVersionTask\build\</GitVersionTaskRoot>
            <GitVersionTaskRoot Condition=""!Exists('$(GitVersionTaskRoot)GitVersionTask.props')"">.\src\GitVersionTask\build\</GitVersionTaskRoot>
            <GitVersionAssemblyFile>{currentDirectory}\..\..\GitVersionTask.MsBuild\bin\$(Configuration)\$(TargetFramework)\GitVersionTask.MsBuild.dll</GitVersionAssemblyFile>
</PropertyGroup>
            <Import Project='$(GitVersionTaskRoot)GitVersionTask.props'/>
            <Import Project='$(GitVersionTaskRoot)GitVersionTask.targets'/>
            </Project>";

            using (var stringReader = new StringReader(projectXml))
            {
                StringBuilder builder;
                Project project;
                bool result;
                using (var collection = new ProjectCollection(globalProperties))
                {
                    builder = new StringBuilder();
                    var writer = new StringWriter(builder);
                    void Handler(string x) => writer.WriteLine(x);
                    var logger = new ConsoleLogger(LoggerVerbosity.Quiet, Handler, null, null);
                    collection.RegisterLogger(logger);
                    XmlReader reader = new XmlTextReader(stringReader);
                    project = collection.LoadProject(reader);
                    result = project.Build();
                    collection.UnregisterAllLoggers();
                }

                var consoleOutput = builder.ToString();
                Console.WriteLine(consoleOutput);

                return (!result, project);
            }
        }

- this is for #1723
- setting the DisableGitVersionTask property to true disables all activities if needed (e.g. NCrunch)
- there is no conditional disabling in the .props file because it must have priority and simple disable it
- the ProjectCollection seems not supported on mono
@DerAlbertCom
Copy link
Author

the change with the current directory at runtime made also the NUnit Test Run Workaround obsolete.

If the tests failed on AppVeyour then the PR check did not really worked.

@arturcic
Copy link
Member

arturcic commented Jul 4, 2019

@DerAlbertCom, I have integrated the changes in the props file, but left the tests out, looks like there are some issues with the tasks running in a unit test. I'll investigate that later. Thanks for your contribution. Please check this version

@arturcic arturcic closed this Jul 4, 2019
@arturcic arturcic added this to the 5.0.0 milestone Jul 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add option to disable the complete GitVersion.Task for building with no existing repositories
2 participants