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

Invalid command line switch for "cmd.exe" System.argumentException: Item has already been added. (PATH vs Path) #232

Closed
TomzBench opened this issue Feb 16, 2021 · 8 comments

Comments

@TomzBench
Copy link
Contributor

Hello,

When building my package with Git Bash shell I receive the following error:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets(238,5): error MSB6001: Invalid command line switch for "cmd.exe". System.ArgumentException: Item has already been added. Key in dictionary: 'Path'  Key being added: 'PATH' [C:\${snip}\build\ZERO_CHECK.vcxproj]

I think this issue is very closely related to this issue: dotnet/msbuild#5726

The problem is not clear how to fix, though MSBUILD suggests that this is a "wontfix" and that I should work around the issue. But it's not clear what to add to my cmake-js usage to work around this issue. It's seems the workaround is required in cmake-js?

@gentunian
Copy link

@TomzBench did you find a workaround for this?

@gentunian
Copy link

I tracked the issue down to nodejs/node#35210 so if this could be backported to older versions of nodejs then this issue I think will disappear.

@gentunian
Copy link

gentunian commented Jun 3, 2021

Going through the code it looks like in master this was addressed as a specific workaround:

if (process.env.Path && process.env.PATH) delete process.env.Path;

If the sanitize in nodejs could be backported, probably that hardfix could be removed as well.

@gentunian
Copy link

Until a new release is out, I'm using the change from that commit as well:

 "cmake-js": "github:cmake-js/cmake-js#e311b71564be3925f35f0861f85817a823d4cff0",

@unbornchikken
Copy link
Member

unbornchikken commented Jul 21, 2021

fixed as of 6.2.1

@gentunian
Copy link

@unbornchikken I tested 6.2.1 and that fix does not solve the issue, it continues there. I added the line from my PR, and that effictively solves the issue:

if (process.platform === "win32" && process.env.Path !== undefined && process.env.PATH !== undefined) {
   const PATH = process.env.Path;
   delete process.env.PATH;
   process.env.Path = PATH;
}

@gentunian
Copy link

to clarify even more...
image
I did that directly to the source in the "node_modules" folder.

@gentunian
Copy link

@unbornchikken current condition won't work because:

if (env.Path && en.PATH && env.Path !== env.PATH)

won't be true when env.Path === env.PATH and you won't delete any. You will still have 2 environament variables, one for Path and other for PATH.

this line:

env.PATH = `$env.Path};${env.PATH}`;

should be in a different inner condition.

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

No branches or pull requests

3 participants