The command exited with code 2 visual studio 2017 - windows

While I'm trying to build my windows application, I'm getting following error.
The command
"C:\repos\CommunityLive\CL_GateApp\signing\StrongNameUnsignedAssemblies.bat
C:\repos\CommunityLive\CL_GateApp\signing" exited with code 2.
Following is my Pre-Build event command line
$(ProjectDir)signing\StrongNameUnsignedAssemblies.bat $(ProjectDir)signing\
Here is the Macros details

Xcopy command without /y can cause this:
This post-build event exited with Code 2:
xcopy $(TargetDir)*.* $(SolutionDir)shared\ /s /i
This worked as hoped:
xcopy $(TargetDir)*.* $(SolutionDir)shared\ /s /i /y

Related

XCopy is not working (File not found *.*)

I'm tyring to copy a folder from my Visual Studio 2015 Project's root directory into the output directory (as it breaks the application without it), so I decided to add xcopy to the post-build commands.
xcopy "$(SolutionDir)Content\*.*" "$(TargetDir)Content\" /s /i /y
I'm getting the following when it runs, and right now I can't even test this application because of xcopy.
1> File not found - *.*
1> 0 File(s) copied
1>C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(4714,5): error MSB3073: The command "xcopy "E:\Data\Projects\Vessel\Games\TheThing\Content\*.*" "E:\Data\Projects\Vessel\Games\TheThing\TheThing\bin\DesktopGL\AnyCPU\Debug\Content\" /s /i /y" exited with code 4.
I'm also getting problems with Xcopy and postbuild events in visual studio from time to time.
My fix is generally to create a batch script which contains the xcopy.
The batch script then is called by:
call "$(SolutionDir)scripts\copyfiles.bat"
as a post script event.

Deleting entire folder in Visual Studio Post-build event

I'm trying to delete a folder in my output directory using the following command line:
del /F "$(TargetDir)Content\"
Tho I always end up exiting with error code 1. I've tried several different ways, without /F, with/without slash both before and after, etc.
Error 1 The command "del /F "E:\proj\bin\Windows\Debug\Content\"" exited with code 1.
There are a lot of questions regarding deleting files in post-build event command lines in visual studio, which works fine, but I can't seem to delete a folder without getting code 1.
Any help is appreciated!
RD /S /Q "Full Path of Folder"
In your case:
RD /S /Q "$(TargetDir)Content\"
Browse to the same folder using Command Prompt, and then run that command and see what the actual error is. Might be permissions or something is in use.

mklink fails from Visual Studio

I have next pre build event:
cmd /C mklink /D /J "$(ProjectDir)SomeDir" "$(ProjectDir)"
This is expanded in(copied from MSBuild output):
cmd /C mklink /D /J "C:\Dir-1\Dir-2\other-dirs-here\SomeDir" "C:\Dir-1\Dir-2\other-dirs-here\"
When running the build with this build event the symbolic link is not created, but when I copy exactly the expanded output of Visual Studio in command line the link is created.
Do you know why?
EDIT: I have administrator rights on the computer. Both Visual Studio and Command Prompt have "Administrator" on top
Found the problem - the previous command in the build event was:
$(ANDROID_HOME)/tools/android.bat update project my-project-settings
and for some weird reasons prevented all commands after it to run...

Post-build event can't be executed

I've converted an old Visual C++ 6.0 project to a new Visual C++ 2010 one. It functions but I have a problem with the post build event which I took from the old project. It registered the target file (an .ocx) on the computer:
copy $(ProjDir)\PDFXChange\dll.Debug\*.* $(TargetDir)
regsvr32 /s /c "$(TargetPath)"
echo regsvr32 exec. time > "$(OutDir)\regsvr32.trg"
In my new solution it doesn't work. I've also tested it in single commands: of the three commands (copy, regsvr32 and echo) only the last one could be executed. What could be my error.
Error:
error MSB3073: The command "copy \PDFXChange\dll.Debug\*.* C:\_tests_\ocx2010\Debug\
regsvr32 /s /c "C:\_tests_\ocx2010\.\Debug\LayoutBox.dll"
echo regsvr32 exec. time > ".\Debug\\regsvr32.trg"
:VCEnd" exited with code 3. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppCommon.targets
COPY and REGSVR32 seem not to work.
The problem was in the name of the macro $(ProjDir). In Visual C++ 2010 it's $(ProjectDir)
$(ProjDir) -> $(Proj ect Dir)
Some macros altered their names (after so many years)!
The command copy \PDFXChange\dll.Debug*.* C:tests\ocx2010\Debug should copy some DLLs into the folder where the next command regsvr32 /s /c "C:tests\ocx2010.\Debug\LayoutBox.dll tried to register the target file. It couldn't find any DLLs there, so it quit with the error message.
Mismatch between
Project->Properties->Configuration Properties->General->Output Directory
and
Project->Properties->Configuration->Linker->Output File
I made the former like so...
$(SolutionDir)$(PlatformTarget)$(Configuration)\
and in the linker like so..
$(SolutionDir)$(PlatformTarget)$(Configuration)$(ProjectName).dll
and it solved the problem

Register dll and ocx file using batch file

I have dll and ocx file on folder on c dirve and want to register just by clicking on batch file
According to this Microsoft knowledge base article:
Regsvr32.exe usage
RegSvr32.exe has the following command-line options:
Regsvr32 [/u] [/n] [/i[:cmdline]] dllname
/u - Unregister server
/i - Call DllInstall passing it an optional [cmdline]; when used with /u calls dll uninstall
/n - do not call DllRegisterServer; this option must be used with /i
/s – Silent; display no message boxes (added with Windows XP and Windows Vista)
When you use Regsvr32.exe, it attempts to load the component and call its DLLSelfRegister function. If this attempt is successful, Regsvr32.exe displays a dialog box that indicates success. If the attempt is unsuccessful, Regsvr32.exe returns an error message. This may include a Win32 error code.
Thus, the resulting batch file will be:
echo off
Regsvr32 /s C:\MyDLL.dll
exit
Try this batch code:
for %%f in (*.ocx *.dll) do regsvr32 %%f
Open Notepad and paste in the code, then save the file as register.bat and run it as an Administrator.
Just put regsvr32 pathto.exe in your batch file, assuming that regsvr32 is on the path.
You'll want to run this in silent mode as multiple errors will possibly cause issues with explorer.exe
for %x in (c:\windows\system32*.dll) do regsvr32 /s %x
Open an Administrative Command Prompt, run the below commands in System32 and SySWoW64 diretories
C:\Windows\System32> for %1 in (*.dll) do regsvr32 /s %1
C:\Windows\SySWow64> for %1 in (*.dll) do regsvr32 /s %1

Resources