Skip to content

Building using dotnet build fails for .NET Standard library project #1175

Closed

Description

@jpierson

I'm using the latest pre-release of GitVersionTask (4.0.0-beta0011) on a .NET standard library project and it seems to work from Visual Studio 2017 but not from the command line using dotnet build. I'm targeting netstandard1.2.

I wasn't sure whether this would work at all. I started off looking around for an implementation that installs a GitVersion package as a DotnetCliToolReference in an SDK csproj file. With nothing conclusive from that or from other .NET Core related issues (ex. #647) I figured I should just try adding the package reference and see what it does. I was happy at first to see it was working when building the solution from Visual Studio but building using dotnet build gives me the following error.

Microsoft (R) Build Engine version 15.1.545.13942
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Users\me.nuget\packages\gitversiontask\4.0.0-beta0011\build\GitVersionTask.targets(45,5): error MSB4062: The "GitVersionTask.WriteVersionInfoToBuildLog" task could not be loaded from the assembly C:\Users\me.nuget\packages\gitversiontask\4.0.0-beta0011\build\GitVersionTask.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL'. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Users\me\source\myproj\src\MyProj\MyProj.csproj]
C:\Program Files\dotnet\sdk\1.0.0-rc4-004771\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(92,5): error : Cannot find project info for 'C:\Users\me\source\myproj\src\MyProj\MyProj.csproj'. This can indicate a missing project reference. [C:\Users\me\source\myproj\src\TestCore\TestCore.csproj]

Build FAILED.

C:\Users\me.nuget\packages\gitversiontask\4.0.0-beta0011\build\GitVersionTask.targets(45,5): error MSB4062: The "GitVersionTask.WriteVersionInfoToBuildLog" task could not be loaded from the assembly C:\Users\me.nuget\packages\gitversiontask\4.0.0-beta0011\build\GitVersionTask.dll. Could not load file or assembly 'Microsoft.Build.Utilities.v4.0, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL'. The system cannot find the file specified. Confirm that the declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [C:\Users\me\source\myproj\src\MyProj\MyProj.csproj]
C:\Program Files\dotnet\sdk\1.0.0-rc4-004771\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Sdk.targets(92,5): error : Cannot find project info for 'C:\Users\me\source\myproj\src\MyProj\MyProj.csproj'. This can indicate a missing project reference. [C:\Users\me\source\myproj\src\TestCore\TestCore.csproj]
0 Warning(s)
2 Error(s)

Time Elapsed 00:00:01.09

According to the documentation:

Support for CoreCLR with dotnet build is coming soon.

Is there anywhere I can follow along with the work being done for getting GitVersionTask or some form of automated solution that works for .NET library projects?

Activity

  1. JakeGinnivan commented on Mar 1, 2017

    @JakeGinnivan
    Contributor

    @onovotny any thoughts? :)

  2. clairernovotny commented on Mar 1, 2017

    @clairernovotny

    Yeah, it cannot work with dotnet build. dotnet build uses the CoreCLR and the tasks are currently compiled for the desktop framework. You have to use msbuild.exe /t:restore,mbbuild.exe /t:build, and msbuild.exe /t:pack as the equiv of dotnet restore, dotnet build and dotnet pack.

    Once GitVersion has .NET Standard versions of the underlying assemblies, we can create .NET Standard build task and support it easily. I believe LibGit2Sharp now has this support as NerdBank.GitVersioning has a .NET Standard version now that uses LibGit2Sharp.

  3. TAGC commented on Mar 15, 2017

    @TAGC

    Which of GitVersion's dependencies are currently blocking progress on the migration?

  4. asbjornu commented on Mar 16, 2017

    @asbjornu
    Member

    @TAGC: Not sure. Here's a dump of GitVersion's packages folder:

    • ApprovalTests.3.0.11
    • ApprovalUtilities.3.0.11
    • Caseless.Fody.1.4.2
    • FluentDateTime.1.13.0
    • Fody.1.29.4
    • GitTools.Core.1.2.1-beta0001
    • GitTools.Testing.1.1.1-beta0001
    • ILRepack.2.0.12
    • JetBrainsAnnotations.Fody.1.0.5.0
    • LibGit2Sharp.0.23.0-pre20160922233542
    • LibGit2Sharp.NativeBinaries.1.0.160
    • Microsoft.CodeAnalysis.Analyzers.1.1.0
    • Microsoft.CodeAnalysis.CSharp.1.3.2
    • Microsoft.CodeAnalysis.Common.1.3.2
    • Microsoft.CodeAnalysis.VisualBasic.1.3.2
    • ModuleInit.Fody.1.5.9.0
    • Mono.Cecil.0.9.6.4
    • NSubstitute.1.10.0.0
    • NUnit.3.6.0
    • NUnit3TestAdapter.3.7.0
    • Newtonsoft.Json.8.0.3
    • ObjectApproval.1.3.0
    • PepitaPackage.1.21.4
    • Shouldly.2.7.0
    • System.Collections.4.3.0
    • System.Collections.Immutable.1.3.1
    • System.Diagnostics.Debug.4.3.0
    • System.Globalization.4.3.0
    • System.Linq.4.3.0
    • System.Reflection.Metadata.1.4.2
    • System.Resources.ResourceManager.4.3.0
    • System.Runtime.4.3.0
    • System.Runtime.Extensions.4.3.0
    • System.Threading.4.3.0
    • TestStack.ConventionTests.3.0.0
    • Visualize.Fody.0.4.5.0
    • YamlDotNet.3.8.0

    I assume most of these need to be ported to .NET Standard before GitVersion can?

  5. conniey commented on Apr 14, 2017

    @conniey

    @asbjornu Yes... or an alternative would have to be found for them.

    The ones that do not exist are:

  6. dazinator commented on Jun 7, 2017

    @dazinator
    Contributor

    Just hit this when running dotnet test on an xunit project, that has a project reference to the project with the gitversion task. I am not sure what the equivalent of dotnet test is for msbuild, however managed to workaround this by:

    1. Build the test project first using msbuild.
    2. dotnet test --no-build to execute the tests.
  7. el2iot2 commented on Jun 25, 2017

    @el2iot2

    Just saw on Twitter that the PR for LibGit2Sharp got merged. That brings this issue one step closer to resolution, it would seem.

  8. el2iot2 commented on Jun 25, 2017

    @el2iot2

    Yep after a quick survey, only PepitaPackage and ApprovalTests don't have netstandard support?

  9. dazinator commented on Jun 27, 2017

    @dazinator
    Contributor

    I don't think ApprovalTests should matter as this is a build time only dependency surely - (i.e for running tests) so shouldn't be a dependency that is forced onto consumers?

  10. dazinator commented on Jun 27, 2017

    @dazinator
    Contributor

    Also just a note to say that even though calling msbuild instead of dotnet cli will provide a workaround for some scenarios, for others, like dotnet ef I can't find any equivalent msbuild commands so this remains a problem.

  11. dazinator commented on Jun 27, 2017

    @dazinator
    Contributor

    I have looked at the dependencies and filtered down the relevent ones for gitversiontask which are:

      <package id="GitTools.Core" version="1.2.1-beta0001" targetFramework="net40" />
      <package id="ILRepack" version="2.0.13" targetFramework="net40" />
      <package id="LibGit2Sharp" version="0.23.0-pre20160922233542" targetFramework="net40" />
      <package id="LibGit2Sharp.NativeBinaries" version="1.0.160" targetFramework="net40" />
      <package id="YamlDotNet" version="3.8.0" targetFramework="net40" />
  12. dazinator commented on Jun 27, 2017

    @dazinator
    Contributor

    Notable we would need to add support for netcore to GitTools.Core first.

  13. dazinator commented on Jun 27, 2017

    @dazinator
    Contributor
  14. asbjornu commented on Jun 28, 2017

    @asbjornu
    Member

    @dazinator: GitTools.Core should be a simple port. But I'm not quite sure what we're using ILRepack for. @JakeGinnivan?

  15. dazinator commented on Jun 28, 2017

    @dazinator
    Contributor

    @asbjornu I started on the port of GitTools.Core but could not get it building yet. Its in a feature branch - If curious see: GitTools/GitTools.Core#40

  16. 26 remaining items

  17. dazinator commented on Jan 23, 2018

    @dazinator
    Contributor

    @tmds Nope I missed it! But I will look at that now!

  18. thestonehead commented on Mar 2, 2018

    @thestonehead

    Is this going to be released any time soon? It would make our CI much easier.

  19. pbalaga commented on Apr 6, 2018

    @pbalaga

    Any news on this one? I think there is still a lot of interest in it. :) What are the blockers as of now?

  20. dazinator commented on Apr 6, 2018

    @dazinator
    Contributor

    Checkout the pr named Netstandard. It has instructions. Short answer is yes you can do this now. Not yet been merged but you can try the PR nuget packages. Let me know how you get on!

  21. pbalaga commented on Apr 6, 2018

    @pbalaga

    Sounds good! Thanks!

  22. TsengSR commented on Apr 6, 2018

    @TsengSR

    Checkout the pr named Netstandard. It has instructions. Short answer is yes you can do this now. Not yet been merged but you can try the PR nuget packages. Let me know how you get on!

    @dazinator: That sounds good though, but can that one be used with the TFS/VSTS pipeline? The only available package for VSTS fromt he store is 3.6.5 one.

    It would be cool to have the 4.x .NET Standard bits packaged within it, and allows us to change the Version via the little "version" drop-down menu? Microsoft does the same with the TFS/VSTS BuildTasks for .NET Core, where they'd set "1." versions as default and "2. (Preview)" (its out of preview by now already) could be chosen manually when needing the newer version?

    I played around with the the GitVersionTask nuget packages including into your project on our VSTS build pipeline, but right now it only works on the hosted Windows Pipelines, not on the linux based ones (due to lack of mono and .NET Core/Standard support).

    Or is the VSTS BuildTask Extension obsolete now with the 4.x versions and we just need to use the dotnet core build task and invoke the cli?

    One bit success I had a few months ago with the Extensions and the nuget packages available form the official nuget feeds (4.0 beta12 preview iirc) was to generate the appropriately assembly versions in AssemblyInfo.cs, but only with the Extension and on Windows Hosted Build Agent.

  23. dazinator commented on Apr 6, 2018

    @dazinator
    Contributor

    That sounds good though, but can that one be used with the TFS/VSTS pipeline? The only available package for VSTS fromt he store is 3.6.5 one.

    The TFS package, and the GEM package aren't being built from the PR branch yet unfortunately.
    To Run on Linux you might try:

    1. Using the dotnet core based docker container?
    2. Using GitVersionTask ? (This will stamp your assemblies during a dotnet build or an msbuild) so doesn't require mono.
    3. Install the GitVersion.CommandLine.DotNetCore nuget package - then invoke that using dotnet cli during your build process. This should run on linux as long as dotnet core is installed.

    Do any of those options help?

    Customising the TFS package is beyond my experience, I would like to get the artifcat being built in the PR branch as a first step!

  24. TsengSR commented on Apr 6, 2018

    @TsengSR

    Will try that in 2 or 3 after my vacation.. GitVersion on TFS/VSTS is a bit of a strange beast.

    On one side we need the assemblies to have a specific version so it can version it on the other side the nuget packages and the build itself, so a mix of both NugetPackage based tasks and cli is required to get proper versioning for CI/CD.

  25. dazinator commented on May 27, 2018

    @dazinator
    Contributor

    Any joy on this?

  26. fleed commented on Jun 18, 2018

    @fleed

    @dazinator how do I get the PR nuget packages?

  27. dazinator commented on Jun 19, 2018

    @dazinator
    Contributor

    @fleed you donate £10 into my bank account and then I email you the package :-)

    On a more seripus note, this is how:

    Checkout the pr named Netstandard. It has instructions. Short answer is yes you can do this now. Not yet been merged but you can try the PR nuget packages. Let me know how you get on!

    it tells you about the CI nuget feed you need to add (hosted on appveyor) and the nuget package version you need to reference.

  28. added a commit that references this issue on Jun 28, 2018
  29. richardgavel commented on Jan 17, 2019

    @richardgavel

    Are we saying there almost needs to be a matrix of GitVersion/NET Core SDK version combinations that are known to work together?

  30. asbjornu commented on Jun 27, 2019

    @asbjornu
    Member

    I believe that after upgrading to LibGit2Sharp 0.26 in #1713, this problem should be fixed. Can you please try the latest build of GitVersion and report back whether it fixes this problem or not? Please reopen this issue if the problem persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions