Skip to content
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

In GitVersion.MsBuild 5.6.3, AfterTargets="GetVersion" causes msbuild warning '"WriteVersionInfoToBuildLog" task could not be loaded' #2533

Closed
philipag opened this issue Jan 12, 2021 · 9 comments
Labels
Milestone

Comments

@philipag
Copy link

The following target dependency causes VS build to generate a warning:

<Target Name="CalculateVersionCodeProperties" AfterTargets="GetVersion;_CompileAppManifest" BeforeTargets="CoreCompile">

The warning:

Warning The "WriteVersionInfoToBuildLog" task could not be loaded from the assembly ...gitversion.msbuild\5.6.3\tools\net48/GitVersion.MsBuild.dll. Method 'RegisterTypes' in type 'GitVersion.MsBuild.GitVersionTaskModule' from assembly 'GitVersion.MsBuild, Version=5.6.3.0, Culture=neutral, PublicKeyToken=null' does not have an implementation. 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.

Expected Behavior

No warning

@philipag philipag added the bug label Jan 12, 2021
@sjoerd222888
Copy link

sjoerd222888 commented Jan 18, 2021

I tested with all nuget package versions out and saw the same behavior.

I assume GitVersion.MsBuild should replace GitVersionTask and has to be used the same way, even though I could not find any documentation. Is my assumption correct?

While GitVersion.MsBuild does not yet work and is not documented, does it make sense to mark GitVersionTask deprecated? Because the replacement seems not ready to me.

@arturcic
Copy link
Member

@sjoerd222888 is not documented I agree with that and there is an issue regarding updating the docs, but you need to understand we spend our free time on maintaining the project, and if we can get some help with that we highly apreciate that. Unfortunately we do not have the time to do everything on time so that's why we need the help of the community, that is how open source works.

While GitVersion.MsBuild does not yet work I cannot agree with that, as out internal tests and integration tests all pass, as well as there are people that were able to do the switch, and are able to use the new package on environments the old one was not working at all.

@AshleighAdams
Copy link

AshleighAdams commented Jan 18, 2021

It's worth noting that I experienced this bug when converting from GitVersionTask to GitVersion.MsBuild too, but cleaning the project and restarting Visual Studio fixed the issue for me. The only other difference (perhaps regression?) I saw was a lot of gitversion.json files being produced, which I threw in my .gitignore.

@arturcic
Copy link
Member

I saw was a lot of gitversion.json

It is on purpose because the implementation of the task is different, the only bug was where the file gets written to, but we addressed that

@sjoerd222888
Copy link

sjoerd222888 commented Jan 18, 2021

I was not able to get beyond the error message, even with cleaning. I will investigate whether I can somehow getting it to work. Just to make sure I am not in another case I post my error message:

Error	MSB4062	The "WriteVersionInfoToBuildLog" task could not be loaded from the assembly 
C:\Users\MyUserName\.nuget\packages\gitversion.msbuild\5.6.3\tools\net48/GitVersion.MsBuild.dll. 
Method 'RegisterTypes' in type 'GitVersion.MsBuild.GitVersionTaskModule' 
from assembly 'GitVersion.MsBuild, Version=5.6.3.0, Culture=neutral, PublicKeyToken=null' 
does not have an implementation. Confirm that the <UsingTask> 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\MyUserName\.nuget\packages\gitversion.msbuild\5.6.3\tools\GitVersion.MsBuild.targets	13	

Worth mentioning that I build for net48 and netcoreapp3.1

<TargetFrameworks>net48;netcoreapp3.1</TargetFrameworks>

I can confirm it work when only building for netcoreapp3.1.

<TargetFramework>netcoreapp3.1</TargetFramework>

And it also works when building solely against net48

<TargetFramework>net48</TargetFramework>

But two target frameworks, net48 and netcoreapp3.1 at the same time seems to cause an issue.

@arturcic Thanks for your feedback, I understand it should work, at least basically. I see your tests work. My feedback was not appropriate with this respect.

@bddckr
Copy link
Contributor

bddckr commented Jan 19, 2021

I think this issue needs more information to be able to resolve this: In my own solution I'm building net462, net5.0, monoandroid10, Xamarin Mac without any issues.

I've been getting issues like this before 5.6.3 as it looks like MSBuild's build processes can't load the same assembly for different target frameworks, once one was already loaded by that process. That was due to GitVersionAssemblyFile getting set to different dlls depending on the projects' target framework. That has since been resolved and is no longer an issue in 5.6.3 anymore.

For the whole solution it now just grabs one dll, i.e. the target frameworks of your projects no longer matter:

<PropertyGroup Condition="'$(MSBuildRuntimeType)' == 'Full' Or '$(MSBuildRuntimeType)' == 'Mono'">
<GitVersionFileExe>$(MSBuildThisFileDirectory)net48/gitversion.exe</GitVersionFileExe>
<GitVersionAssemblyFile>$(MSBuildThisFileDirectory)net48/GitVersion.MsBuild.dll</GitVersionAssemblyFile>
</PropertyGroup>
<PropertyGroup>
<GitVersionFileExe Condition="'$(GitVersionFileExe)' == ''">dotnet --roll-forward Major $(MSBuildThisFileDirectory)netcoreapp3.1/gitversion.dll</GitVersionFileExe>
<GitVersionAssemblyFile Condition="'$(GitVersionAssemblyFile)' == ''">$(MSBuildThisFileDirectory)netcoreapp3.1/GitVersion.MsBuild.dll</GitVersionAssemblyFile>
</PropertyGroup>

I'm on VS on Windows, using version 16.8.4. The error sounds like either the dll is broken, or perhaps you're on a preview VS release and there's a dependency issue? Perhaps try this to ensure you're trying from a clean state:

  1. Turn off all instances of VS.
  2. Clear your solution's build folders (all bin + obj folders).
  3. Go to your NuGet packages folder (%userprofile%/.nuget/packages by default) and delete the gitversion.msbuild folder to ensure VS grabs a new copy.

Then again, you're saying it works if you only build one project at a time? 🤔

@philipag
Copy link
Author

@bddckr I tried to test whether this is a problem only in the VS pre-release. So I rebuilt my solution with the VS release version and the problem was gone. Then I rebuilt with the preview and the problem is still gone!

I don't know what caused the warning to go away. A windows update recently caused my computer to reboot so perhaps a reboot is helpful after uninstalling GitVersionTask and installing GitVersion.MsBuild 5.6.3?

@arturcic
Copy link
Member

Closing this one, it should be fixed in 6.0.0-beta3

@arturcic arturcic added this to the 6.x milestone Apr 13, 2023
@arturcic arturcic modified the milestones: 6.x, 6.0.0-beta.3 Jun 26, 2023
@arturcic
Copy link
Member

🎉 This issue has been resolved in version 6.0.0-beta.3 🎉
The release is available on:

Your GitReleaseManager bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants