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

Error: An item with the same key has already been added while running Cake from commit hooks #1319

Closed
vengi83644 opened this issue Oct 27, 2016 · 11 comments · Fixed by #1320
Closed
Labels
Milestone

Comments

@vengi83644
Copy link

Below is the process we are doing

From Commit Hook file
exec powershell -Command "& '$REPOSITORYPATH/build.ps1' -Script '$REPOSITORYPATH/build.cake'"

From Build.ps1
Invoke-Expression "& "$CAKE_EXE" "$Script" -verbosity="$Verbosity""

From Build.cake - a simple task to clean directories
var target = Argument("target", "Default");
var configuration = Argument("configuration", "Release");

Task("Clean")
.Does(() =>
{
    CleanDirectories("**/bin/");
    CleanDirectories("**/obj/");
    DeleteFiles(GetFiles("./**/*FxCopAnalysis.xml"));
    DeleteFiles(GetFiles("./**/*StyleCopAnalysis.xml"));
});

Also, we have discussed this in the below gitter.
https://gitter.im/cake-build/cake?at=5811a7d75a1cfa016e4f992f

Reproduced issue mentioned in the below link.
https://gitter.im/cake-build/cake?at=5811aa598ed1c0ff5c32e357

devlead added a commit to devlead/cake that referenced this issue Oct 27, 2016
devlead added a commit to devlead/cake that referenced this issue Oct 27, 2016
@devlead
Copy link
Member

devlead commented Oct 27, 2016

@vijays-git @vengi83644 PR submitted, artifacts available here, could you please test if it sorts your issue.

Cake-bin-net45-v0.17.0-PullRequest1320.zip should contain what you need.

@vengi83644
Copy link
Author

@devlead I tried putting all the files from this zip to the tools/cake folder and got the below issues

Cake-bin-net45-v0.17.0-PullRequest1321.zip
The above results the same issue

Cake-bin-net45-v0.17.0-PullRequest1320.zip

Error: Could not load file or assembly 'tools\Cake\Roslyn.Compilers.CSharp.dll' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)
From the 1320 artifact I get this assembly load error

@devlead
Copy link
Member

devlead commented Oct 27, 2016

@vijays-git @vengi83644 think I know why, delete all files except below (the rest will be downloaded at first run)

Cake.exe
Cake.Core.dll
Cake.Core.xml
Cake.NuGet.dll
Cake.NuGet.xml
Cake.Common.dll
Cake.Common.xml
NuGet.Core.dll
Mono.CSharp.dll
Autofac.dll

@vengi83644
Copy link
Author

I did the below steps
I have deleted the contents in the cake folder
copied the above files October 27, 2016 7:33 AM from the 1320 artifact
Got the same issue again
Error: An item with the same key has already been added.

@devlead
Copy link
Member

devlead commented Oct 27, 2016

Mattias Karlsson @devlead 14:37
@vengi83644 what does Cake.exe --version tell you?

Venkatesan R @vengi83644 14:38
Version 0.16.2+Branch.main.Sha.fb23be463dacfa51c9b19a7cd111149dda7e8c6b

Mattias Karlsson @devlead 14:39
then you've got the wrong version
should say Version 0.17.0-PullRequest.1320+94.Branch.pull/1320/merge.Sha.6ead74a349d55b5890fc7af17b57de2340840732

As per gitter discussion, you can verify running correct version once unzipped using file properties
image

Also check to other Cake in path. i.e. enter full path to Cake.exe to make sure you're running correct version.

@devlead devlead added this to the v0.17.0 milestone Oct 27, 2016
@devlead devlead added the Bug label Oct 27, 2016
devlead added a commit to devlead/cake that referenced this issue Oct 27, 2016
gep13 pushed a commit to devlead/cake that referenced this issue Oct 28, 2016
@vengi83644
Copy link
Author

vengi83644 commented Oct 28, 2016

https://gitter.im/cake-build/cake?at=58139604806316005dce3c08

Now I have commented the below codes and this worked.
#$NuGetOutput = Invoke-Expression "&"$NUGET_EXE" install -ExcludeVersion -OutputDirectory "$TOOLS_DIR""

#if ($LASTEXITCODE -ne 0) {
#Throw "An error occured while restoring NuGet tools."
#}

else

{

#    $md5Hash | Out-File $PACKAGES_CONFIG_MD5 -Encoding "ASCII"
#}
#Write-Host -Message ($NuGetOutput | out-string)
#Pop-Location

@vengi83644
Copy link
Author

I am getting same error now for NuGet package restore task.

Restore-NuGet-Packages

Executing task: Restore-NuGet-Packages

slnFile Test.sln

An error occured when executing task 'Restore-NuGet-Packages'.

Error: Item has already been added. Key in dictionary: 'home' Key being added: 'HOME'

@devlead
Copy link
Member

devlead commented Oct 28, 2016

As this is merged it'll be in the next release, already avail on our MyGet feed. This Stackoverflow answer describes how to use prerelease version of Cake:
http://stackoverflow.com/a/40260724/5883153

@devlead
Copy link
Member

devlead commented Oct 28, 2016

Could you run Cake with diagnostic debugging so we get a full stack trace?

@vengi83644
Copy link
Author

Yes. Here is the Stack
It happens
at Cake.Core.Polyfill.ProcessHelper.SetEnvironmentVariable(ProcessStartInfo info, String key, String value)

Preparing to run build script...

-Message Restoring tools from NuGet...

Running build script...

Module directory does not exist.

Analyzing build script...

Analyzing /build.cake...

Processing build script...

Creating script session...

Adding reference to mscorlib.dll...

Adding reference to System.Core.dll...
Adding reference to Cake.Core.dll...
Adding reference to Cake.Common.dll...
Adding reference to Cake.exe...
Adding reference to System.dll...
Adding reference to System.Xml.dll...
Adding reference to System.Xml.Linq.dll...
Adding reference to System.Data.dll...
Importing namespace Cake.Common...
Importing namespace Cake.Common.Build...
Importing namespace Cake.Common.Build.AppVeyor...
Importing namespace Cake.Common.Build.AppVeyor.Data...
Importing namespace Cake.Common.Build.BitbucketPipelines...
Importing namespace Cake.Common.Build.BitbucketPipelines.Data...
Importing namespace Cake.Common.Build.Bitrise...
Importing namespace Cake.Common.Build.Bitrise.Data...
Importing namespace Cake.Common.Build.ContinuaCI...
Importing namespace Cake.Common.Build.ContinuaCI.Data...
Importing namespace Cake.Common.Build.GitLabCI...
Importing namespace Cake.Common.Build.GitLabCI.Data...
Importing namespace Cake.Common.Build.GoCD...
Importing namespace Cake.Common.Build.GoCD.Data...
Importing namespace Cake.Common.Build.Jenkins...
Importing namespace Cake.Common.Build.Jenkins.Data...
Importing namespace Cake.Common.Build.TFBuild...
Importing namespace Cake.Common.Build.TFBuild.Data...
Importing namespace Cake.Common.Build.TravisCI...
Importing namespace Cake.Common.Build.TravisCI.Data...
Importing namespace Cake.Common.Diagnostics...
Importing namespace Cake.Common.IO...
Importing namespace Cake.Common.IO.Paths...
Importing namespace Cake.Common.Net...
Importing namespace Cake.Common.Security...
Importing namespace Cake.Common.Solution...
Importing namespace Cake.Common.Solution.Project...
Importing namespace Cake.Common.Solution.Project.Properties...
Importing namespace Cake.Common.Solution.Project.XmlDoc...
Importing namespace Cake.Common.Text...
Importing namespace Cake.Common.Tools...
Importing namespace Cake.Common.Tools.Cake...
Importing namespace Cake.Common.Tools.Chocolatey...
Importing namespace Cake.Common.Tools.Chocolatey.ApiKey...
Importing namespace Cake.Common.Tools.Chocolatey.Config...
Importing namespace Cake.Common.Tools.Chocolatey.Features...
Importing namespace Cake.Common.Tools.Chocolatey.Install...
Importing namespace Cake.Common.Tools.Chocolatey.Pack...
Importing namespace Cake.Common.Tools.Chocolatey.Pin...
Importing namespace Cake.Common.Tools.Chocolatey.Push...
Importing namespace Cake.Common.Tools.Chocolatey.Sources...
Importing namespace Cake.Common.Tools.Chocolatey.Upgrade...
Importing namespace Cake.Common.Tools.DNU...
Importing namespace Cake.Common.Tools.DNU.Build...
Importing namespace Cake.Common.Tools.DNU.Pack...
Importing namespace Cake.Common.Tools.DNU.Restore...
Importing namespace Cake.Common.Tools.DotCover...
Importing namespace Cake.Common.Tools.DotCover.Analyse...
Importing namespace Cake.Common.Tools.DotCover.Cover...

Importing namespace Cake.Common.Tools.DotCover.Report...
Importing namespace Cake.Common.Tools.DotNetCore...
Importing namespace Cake.Common.Tools.DotNetCore.Build...
Importing namespace Cake.Common.Tools.DotNetCore.Execute...
Importing namespace Cake.Common.Tools.DotNetCore.Pack...
Importing namespace Cake.Common.Tools.DotNetCore.Publish...
Importing namespace Cake.Common.Tools.DotNetCore.Restore...
Importing namespace Cake.Common.Tools.DotNetCore.Run...
Importing namespace Cake.Common.Tools.DotNetCore.Test...

Importing namespace Cake.Common.Tools.DupFinder...
Importing namespace Cake.Common.Tools.Fixie...
Importing namespace Cake.Common.Tools.GitLink...

Importing namespace Cake.Common.Tools.GitReleaseManager...
Importing namespace Cake.Common.Tools.GitReleaseManager.AddAssets...
Importing namespace Cake.Common.Tools.GitReleaseManager.Close...
Importing namespace Cake.Common.Tools.GitReleaseManager.Create...
Importing namespace Cake.Common.Tools.GitReleaseManager.Export...

Importing namespace Cake.Common.Tools.GitReleaseManager.Publish...
Importing namespace Cake.Common.Tools.GitReleaseNotes...
Importing namespace Cake.Common.Tools.GitVersion...
Importing namespace Cake.Common.Tools.ILMerge...
Importing namespace Cake.Common.Tools.ILRepack...
Importing namespace Cake.Common.Tools.InnoSetup...
Importing namespace Cake.Common.Tools.InspectCode...
Importing namespace Cake.Common.Tools.MSBuild...
Importing namespace Cake.Common.Tools.MSTest...
Importing namespace Cake.Common.Tools.NSIS...
Importing namespace Cake.Common.Tools.NuGet...
Importing namespace Cake.Common.Tools.NuGet.Install...
Importing namespace Cake.Common.Tools.NuGet.Pack...
Importing namespace Cake.Common.Tools.NuGet.Push...
Importing namespace Cake.Common.Tools.NuGet.Restore...
Importing namespace Cake.Common.Tools.NuGet.SetApiKey...
Importing namespace Cake.Common.Tools.NuGet.SetProxy...
Importing namespace Cake.Common.Tools.NuGet.Sources...
Importing namespace Cake.Common.Tools.NuGet.Update...

Importing namespace Cake.Common.Tools.NUnit...
Importing namespace Cake.Common.Tools.OctopusDeploy...
Importing namespace Cake.Common.Tools.OpenCover...

Importing namespace Cake.Common.Tools.ReportGenerator...

Importing namespace Cake.Common.Tools.ReportUnit...

Importing namespace Cake.Common.Tools.Roundhouse...

Importing namespace Cake.Common.Tools.SignTool...
Importing namespace Cake.Common.Tools.SpecFlow...

Importing namespace Cake.Common.Tools.SpecFlow.StepDefinitionReport...

Importing namespace Cake.Common.Tools.SpecFlow.TestExecutionReport...

Importing namespace Cake.Common.Tools.TextTransform...
Importing namespace Cake.Common.Tools.VSTest...

Importing namespace Cake.Common.Tools.WiX...

Importing namespace Cake.Common.Tools.WiX.Heat...

Importing namespace Cake.Common.Tools.XBuild...

Importing namespace Cake.Common.Tools.XUnit...

Importing namespace Cake.Common.Xml...
Importing namespace Cake.Core...
Importing namespace Cake.Core.Diagnostics...
Importing namespace Cake.Core.IO...
Importing namespace Cake.Core.Scripting...
Importing namespace System...
Importing namespace System.Collections.Generic...
Importing namespace System.IO...
Importing namespace System.Linq...
Importing namespace System.Text...
Importing namespace System.Threading.Tasks...

Compiling build script...

Clean

Executing task: Clean

The provided pattern did not match any directories.

The provided pattern did not match any directories.

Deleting file .FxCopAnalysis.xml
Deleting file .FxCopAnalysis.xml

Deleting file .StyleCopAnalysis.xml

Deleting file .StyleCopAnalysis.xml

Finished executing task: Clean

Restore-NuGet-Packages

Executing task: Restore-NuGet-Packages

slnFile E:/test/Server/Base Projects/test/Test.sln

Executing: "E:/test/Server/Base Projects/test/tools/NuGet.exe" restore "E:/test/Server/Base Projects/test/Test.sln" -NonInteractive
An error occured when executing task 'Restore-NuGet-Packages'.
Error: System.ArgumentException: Item has already been added. Key in dictionary: 'home' Key being added: 'HOME'
at System.Collections.Hashtable.Insert(Object key, Object nvalue, Boolean add)
at System.Diagnostics.ProcessStartInfo.get_EnvironmentVariables()
at Cake.Core.Polyfill.ProcessHelper.SetEnvironmentVariable(ProcessStartInfo info, String key, String value)
at Cake.Core.IO.ProcessRunner.Start(FilePath filePath, ProcessSettings settings)
at Cake.Core.Tooling.Tool1.RunProcess(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings) at Cake.Core.Tooling.Tool1.Run(TSettings settings, ProcessArgumentBuilder arguments, ProcessSettings processSettings, Action1 postAction) at Cake.Core.Tooling.Tool1.Run(TSettings settings, ProcessArgumentBuilder arguments)
at Cake.Common.Tools.NuGet.Restore.NuGetRestorer.Restore(FilePath targetFilePath, NuGetRestoreSettings settings)
at Cake.Common.Tools.NuGet.NuGetAliases.NuGetRestore(ICakeContext context, FilePath targetFilePath, NuGetRestoreSettings settings)
at Cake.Common.Tools.NuGet.NuGetAliases.NuGetRestore(ICakeContext context, FilePath targetFilePath)
at Submission#0.<.ctor>b__2()
at Cake.Core.CakeTaskBuilderExtensions.<>c__DisplayClass5_0.b__0(ICakeContext context)

at Cake.Core.ActionTask.Execute(ICakeContext context)
at Cake.Core.DefaultExecutionStrategy.Execute(CakeTask task, ICakeContext context)
at Cake.Core.CakeEngine.ExecuteTask(ICakeContext context, IExecutionStrategy strategy, Stopwatch stopWatch, CakeTask task, CakeReport report)
at Cake.Core.CakeEngine.RunTarget(ICakeContext context, IExecutionStrategy strategy, String target)
at Cake.Scripting.BuildScriptHost.RunTarget(String target)
at Submission#0..ctor(Session session, Object& submissionResult)
at Submission#0.(Session session)
at Roslyn.Scripting.CommonScriptEngine.Execute[T](String code, String path, DiagnosticBag diagnostics, Session session, Boolean isInteractive)
at Roslyn.Scripting.Session.Execute(String code)
at Cake.Scripting.Roslyn.Stable.DefaultRoslynScriptSession.Execute(Script script)
at Cake.Core.Scripting.ScriptRunner.Run(IScriptHost host, FilePath scriptPath, IDictionary`2 arguments)
at Cake.Commands.BuildCommand.Execute(CakeOptions options)
at Cake.CakeApplication.Run(CakeOptions options)
at Cake.Program.Main()

@devlead
Copy link
Member

devlead commented Oct 28, 2016

@vengi83644 Thanks, that helps a lot, I'll submit PR to address this once I'm at a computer.

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

Successfully merging a pull request may close this issue.

2 participants