Launching devenv from git-bash gives build error - visual-studio-2010

I need to launch a build of my solution from gitbash. I am on visual studio 2010 running with the VS2003 toolset.
For that I call a .bat file which builds the solution from the devenv.exe switch command.
Running the bat file on its own is fine. However, running it from gitbash fails the build.
bat file:
"C:\...pathToDevenv...\IDE\devenv.exe" MySolution.sln /Build "Debug" /out BuildReport.log
call from git-bash:
./compileMySolution.bat
I get this error:
error MSB6001: Invalid command line switch for "CL.exe". Item has already been added. Key in dictionary: 'HOME' Key being added: 'home'
Build FAILED.
I tried to set a home environment variable but failed.
I found no clue in the file Microsoft.Cpp.Win32.v71.targets(309,5).
Can someone help me? thanks

Finally I just unset the HOME variable in the shell and set it in the .bat file.

Related

Build Visual Studio C++ project/solution from command line

I am trying to compile a Visual Studio 2019 project or solution using msbuild. But when I'm running a command, an error pops up in the command line
MSBUILD : error MSB1009: Project file does not exist.
Key: TestProject.sln
Here code that im using in .bat file:
set pathMSBuild = "C:\Windows\Microsoft.NET\Framework64\v4.0.30319\"
#echo off
cls
cd %pathMSBuild%
msbuild C:\TestProject\TestProject\TestProject.sln
pause
I don't understand why this is happening because I have specified the correct path to the project on the disk and I have it there. Any ideas why its happens?

VS2019 - msbuild is not recognized as internal or external command

I am using VS2019 community and I've set pre-build event:
msbuild "$(ProjectPath)" /t:Clean
I am getting error:
'MSBuild' is not recognized as an internal or external command,
operable program or batch file
How is this possible? Isn't this command supposed to be build into visual studio?
I've checked this and tried to set path environment, but it doesn't help.
Does anybody else has the same problem with this command in VS2019?
Steps that work in my machine:
See this, first we need to make sure MSBuild can be recognized by cmd.exe.
If the command can be recognized by cmd.exe but not build-event from VS, restart the PC can help resolve this issue.
(Something strange is that for my VS still can't recognize it until a restart of the computer)
For VS2019, the correct msbuild path is C:\Program Files (x86)\Microsoft Visual Studio\2019\xxx\MSBuild\Current\Bin
And here's another workaround:
Apart from adding the path of msbuild.exe into Environment Path and call it in pre-build event, you can also consider using MSBuild Task.
Add script below into xx.csproj:(work for .net framework...)
<Target Name="MyCleanBeforeBuild" BeforeTargets="BeforeBuild">
<MSBuild Projects="$(ProjectPath)" Targets="clean"/>
<!--<Message Text="Custom Clean" Importance="high"/>-->
</Target>
With latest update to VS2019 - version 16.3.4 - the error is no longer there.
Using "dotnet" instead of "msbuild" could work if you got that installed.
So, in my case, instead of running "msbuild /t:restore" I figured I can use "dotnet build" and have the same result.
Here's the documentation in case you want to see more equivalent commands.
https://learn.microsoft.com/en-us/dotnet/core/tools/

Grunt JS Task Runner - Tasks directory not found, Task "vs-grunt-task-reader" not found - File path prefixed with /c$/

I've just started at a new company and we pulled all the code from source to my local computer. Everything runs fine, except the Task Runner Explorer is failing to run Gruntfile.js because it can't find vs-grunt-task-reader.js
Here's the error:
Failed to run "C:\Projects\DQ2 Application\deltaquestv2_frontend\DeltaQuest2\DeltaQuest2\DQ2-Client\Gruntfile.js"...
Then:
Tasks directory "\c$\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\TaskRunnerExplorer\Scripts" not found.
Warning: Task "vs-grunt-task-reader" not found.
And the command that fails:
cmd.exe /c grunt -b "C:\Projects\DQ2 Application\deltaquestv2_frontend\DeltaQuest2\DeltaQuest2\DQ2-Client" --gruntfile "C:\Projects\DQ2 Application\deltaquestv2_frontend\DeltaQuest2\DeltaQuest2\DQ2-Client\Gruntfile.js" --tasks "\c$\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\TaskRunnerExplorer\Scripts" vs-grunt-task-reader
When I run the command in cmd, I get the same message, but when I change the \c$to C:, it works runs successfully.
Is there a way to change the \c$ to C: within Visual Studio or the Grunt config?
Or is there any reason why the Grunt Task Runner runs fine on one computer and not mine?
Not sure if this makes any difference to this question, but if I run "\myComputerName\c$" it opens C: in explorer
I found a tutorial on setting up Grunt in Visual Studio 2015, and the first thing it says to do is: "Install Web Essential 2015 from Tools / Extensions and Updates".
Problem solved!
https://dvoituron.com/2015/07/15/grunt-and-bower-in-visual-studio-2015/

Running Grunt from Visual Studio post build event command line

I've attempted to do this both in Visual Studio 2010 and Visual Studio 2012. If my Gruntfile.js file is in the root of my project I can run the "grunt" command from the post build event command line and it runs without a problem.
grunt or grunt.cmd
But if it's in a sub directory
$(ProjectDir)Public\grunt or $(ProjectDir)Public\grunt.cmd
It gives me this error
The command "c:\web\Public\grunt.cmd" exited with code 9009.
I've been researching this but I'm not finding any much help out there. I did find in the grunt documentation that I need to use "grunt.cmd" instead of just calling "grunt" but thats not helping me much.
What's happening is you're specifying an exact path for grunt, which doesn't actually reside at $(ProjectDir)Public\. When you're in that directory on a command prompt and type grunt, it executes because you've set your path environment variable to include the directory where grunt lives.
Luckily the post build commands in VS act like a command window, so you can put this in your post build commands:
CD $(ProjectDir)Public\
grunt
And that should work (assuming a default grunt task is defined).
If you had Visual Studio open and then:
Installed node package manager (npm) and grunt
Then tried to run pre/post build commands including grunt command.
The build will simply fail with the "exited with code 9009" message. (Meaning "I don't know what grunt command is")
To resolve this situation just close visual studio and reopen it (as #longda mentioned on his comment) and everything will work just fine.
I'm using VS 2013 Premium and latest version of npm/grunt.
You can run as post build using task runner as shown below.
Right click on the build --> bindings--> and then specify if you need it to run post or pre build
Somewhat related, I had a weird issue that xcopy would not run after grunt, running them as a single command fixed it:
cd $(SolutionDir)..\App
grunt release && xcopy "$(SolutionDir)..\App\release" "$(TargetDir)Content\" /Y /E /S

`msbuild` command not found, but `msbuild.exe` works fine

I run MSys/Bash as distributed in Git for Windows. I added the folder C:\Windows\Microsoft.NET\Framework\v4.0.30319 to my path, so I could run msbuild but it doesn't work
$ msbuild
C:\Program Files (x86)\Git\bin\sh.exe: msbuild: command not found
Yet msbuild.exe does:
$ msbuild.exe
Microsoft (R) Build Engine version 4.0.30319.17929
Yet the command explorer resolves fine. What's going on?
It's a bug in MSys where the same name is shared by a folder and a file (minus the extension). In this case:
File C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
Folder C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild
You'll have to workaround by writing msbuild.exe
If the exe file outputs not found, do copy C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe ProjectPath
And then run msbuild.exe
If msbuild.exe cannot be found, it needs to be configured.
Open a command prompt and run the file vsvars32.bat located in your Visual Studio Common7/Tools folder..
i.e C:\Program Files x86\Microsoft Visual Studio 12.0\Common7\Tools\vsvars32.bat
This will correctly setup all the neccessary variables for msbuild.exe to be found.

Resources