GitTools / GitVersion

From git log to SemVer in no time
https://gitversion.net/docs/
MIT License
2.85k stars 650 forks source link

4.0.1-beta1-58: dotnet build crashes with error MSB4044: The "GetAssemblyVersion" task was not given a value for the required parameter "NuGetVersion" #1557

Closed wjrogers closed 5 years ago

wjrogers commented 5 years ago

My project is multi-targeting net471 and netcoreapp2.1. The same error occurs when I build both targets and when I build either one individually.

There is a mismatch between SDK NuGet version (4.9.2) and the NuGet version the task factory was compiled against (4.9.0).
[NuGet Minimal]: Restoring packages for C:\Users\will\.nuget\packages\gitversiontask\4.0.1-beta1-58\build\functionality\GitVersionBuild.targets...
[NuGet Minimal]: Restoring packages for C:\Users\will\.nuget\packages\gitversiontask\4.0.1-beta1-58\build\functionality\GitVersionBuild.targets...
There is a mismatch between SDK NuGet version (4.9.2) and the NuGet version the task factory was compiled against (4.9.0).
MSBUILD : warning : WARN [12/21/18 11:25:46:12] Could not determine assembly version: System.Runtime.InteropServices.MarshalDirectiveException: StrictFilePathMarshaler must be used on a FilePath. [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at LibGit2Sharp.Core.StrictFilePathMarshaler.MarshalManagedToNative(Object managedObj) in C:\projects\libgit2sharp\LibGit2Sharp\Core\FilePathMarshaler.cs:line 71 [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at System.StubHelpers.MngdRefCustomMarshaler.ConvertContentsToNative(IntPtr pMarshalState, Object& pManagedHome, IntPtr pNativeHome) [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at LibGit2Sharp.Core.NativeMethods.git_repository_discover(GitBuf buf, FilePath start_path, Boolean across_fs, FilePath ceiling_dirs) [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at LibGit2Sharp.Core.Proxy.ConvertPath(Func`2 pathRetriever) in C:\projects\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 3553 [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at LibGit2Sharp.Repository.Discover(String startingPath) in C:\projects\libgit2sharp\LibGit2Sharp\Repository.cs:line 645 [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at GitVersion.GitPreparer.GetDotGitDirectory() in C:\projects\gitversion\src\GitVersionCore\GitPreparer.cs:line 163 [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig, Boolean noCache) in C:\projects\gitversion\src\GitVersionCore\ExecuteCore.cs:line 33 [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at GitVersion.ExecuteCore.TryGetVersion(String directory, VersionVariables& versionVariables, Boolean noFetch, Authentication authentication) in C:\projects\gitversion\src\GitVersionCore\ExecuteCore.cs:line 82 [C:\Work\Redacted\Redacted\Redacted.csproj]
There is a mismatch between SDK NuGet version (4.9.2) and the NuGet version the task factory was compiled against (4.9.0).
MSBUILD : warning : WARN [12/21/18 11:25:46:20] Could not determine assembly version: System.Runtime.InteropServices.MarshalDirectiveException: StrictFilePathMarshaler must be used on a FilePath. [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at LibGit2Sharp.Core.StrictFilePathMarshaler.MarshalManagedToNative(Object managedObj) in C:\projects\libgit2sharp\LibGit2Sharp\Core\FilePathMarshaler.cs:line 71 [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at System.StubHelpers.MngdRefCustomMarshaler.ConvertContentsToNative(IntPtr pMarshalState, Object& pManagedHome, IntPtr pNativeHome) [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at LibGit2Sharp.Core.NativeMethods.git_repository_discover(GitBuf buf, FilePath start_path, Boolean across_fs, FilePath ceiling_dirs) [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at LibGit2Sharp.Core.Proxy.ConvertPath(Func`2 pathRetriever) in C:\projects\libgit2sharp\LibGit2Sharp\Core\Proxy.cs:line 3553 [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at LibGit2Sharp.Repository.Discover(String startingPath) in C:\projects\libgit2sharp\LibGit2Sharp\Repository.cs:line 645 [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at GitVersion.GitPreparer.GetDotGitDirectory() in C:\projects\gitversion\src\GitVersionCore\GitPreparer.cs:line 163 [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at GitVersion.ExecuteCore.ExecuteGitVersion(String targetUrl, String dynamicRepositoryLocation, Authentication authentication, String targetBranch, Boolean noFetch, String workingDirectory, String commitId, Config overrideConfig, Boolean noCache) in C:\projects\gitversion\src\GitVersionCore\ExecuteCore.cs:line 33 [C:\Work\Redacted\Redacted\Redacted.csproj]
MSBUILD : warning :    at GitVersion.ExecuteCore.TryGetVersion(String directory, VersionVariables& versionVariables, Boolean noFetch, Authentication authentication) in C:\projects\gitversion\src\GitVersionCore\ExecuteCore.cs:line 82 [C:\Work\Redacted\Redacted\Redacted.csproj]
C:\Program Files\dotnet\sdk\2.1.502\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.GenerateAssemblyInfo.targets(161,5): error MSB4044: The "GetAssemblyVersion" task was not given a value for the required parameter "NuGetVersion". [C:\Work\Redacted\Redacted\Redacted.csproj]
bonesoul commented 5 years ago

same here.

twsl commented 5 years ago

Same problem without multitargeting, only netcoreapp22/netstandard20

rafamerlin commented 5 years ago

Hey guys, had the same issue, but on version 4.0.0 (not the beta). The reason was I had just created a new project and added Gitversion without ever committing anything to the project. After I created my first commit the issue stopped happening.

Possibly not the same issue though.

twsl commented 5 years ago

Still no fix?

thestonehead commented 5 years ago

I have this problem on 4.0.0, but not on 4.0.0-beta0012

arturcic commented 5 years ago

Can you guys give it a try to this version

arturcic commented 5 years ago

As LibGit2Sharp was upgraded to version 0.26 in #1713, I think this problem is fixed. Please reopen this issue if the problem persists.

thoemmi commented 5 years ago

@arturcic The original bug is fixed, thanks. However, it seems like beta4 introduced a new issue: GitVersionTool generates multiple assembly version files.

In obj/Debug/<target framework>/ there are three(!) files with AssemblyFileVersion generated. E.g. _AssemblyInfo_TinyLittleMvvmluhkzhpu.hpc.g.cs, _AssemblyInfo_TinyLittleMvvmvldmbkmg.upl.g.cs, and TinyLittleMvvm.AssemblyInfo.cs. The first two files contain only the attributes AssemblyFileVersion, AssemblyVersion, and AssemblyInformationalVersion, and the last file contains all assembly level attributes.

This results in many error CS0579: Duplicate 'System.Reflection.AssemblyXxxAttribute' attribute errors. E.g. see the output of my latest build.

arturcic commented 5 years ago

Gave you followed these steps? https://gitversion.readthedocs.io/en/latest/usage/msbuild-task/, the Remove AssemblyInfo attributes step I mean

arturcic commented 5 years ago

I guess in your case it's an sdk project, then you should add this <GenerateAssemblyInfo>false</GenerateAssemblyInfo>

thoemmi commented 5 years ago

Thanks for the pointer. In the past it worked without that property. I'll try it tomorrow.

thoemmi commented 5 years ago

Well, the GenerateAssemblyInfo indeed disables generating the AssemblyInfo. However, that file also includes all the assembly attributes, such as AssemblyProduct, AssemblyTitle, AssemblyCopyright and so forth.

The correct way is to set <UpdateAssemblyInfo>false</UpdateAssemblyInfo>. In this case, GitVersion won't generate its own AssemblyInfo file, but set the necessary MSBuild properties, and the SDK build will write the correct values to its AssemblyInfo.

Mexicoder commented 5 years ago

I'm still having this issue with my .net core 2.2 web project. i have tried the steps suggested but still getting the same error. Any other suggestions?

bonesoul commented 5 years ago

same issue on dot net core 3 project

jmevel commented 3 years ago

Hey guys, had the same issue, but on version 4.0.0 (not the beta). The reason was I had just created a new project and added Gitversion without ever committing anything to the project. After I created my first commit the issue stopped happening.

Possibly not the same issue though.

This helped me a lot. In my case this was because I checked out a specific commit in git. I just created a new branch on this commit and the issue disappeared

MolotovCherry commented 11 months ago

For anyone coming from Google, this was near impossible for me to track down, but it turned out it was simply because all the source files in my project were LF instead of CRLF.

Which was the reason why it sometimes worked when doing different git things like git branching, git stashing, etc, but kept re-appearing randomly for some inexplicable reason

deadlydog commented 1 month ago

For others coming here because they searched the error message

The "GetAssemblyVersion" task was not given a value for the required parameter "NuGetVersion"

for me the problem was I was only specifying the Version parameter in my build script, and needed to specify the AssemblyVersion as well.

That is, I changed this:

dotnet build "$path" -p:Version=$versionNumber --configuration Release

Which would give the error, to this:

dotnet build "$path" -p:AssemblyVersion=$versionNumber -p:Version=$versionNumber --configuration Release

And that fixed it up for me.