XCopy failing during build but not from command line? - c#

I have a console program that outputs its exe & dlls to a specified directory.
As a post build event I am trying to copy everything in that directory to another directory.
My xcopy command works from command prompt but fails in VS2010? How can this be?
I am testing it by going to the project folder and executing the following in command prompt. (it is the output from VS2010)
In my post-build event:
xcopy "$(OutDir)*.*" "$(TargetDir)..\..\Foo\Bar\" /s /y /i
From command prompt I am executing the following which works.
xcopy "..\..\..\..\MyDir\baz\zip\*.*" "c:\1\2\3\MyDir\baz\zip\..\..\Foo\Bar\" /s /y /i
Sorry about the directory names.
End result should be two directories with the same files in them:
c:\1\2\3\MyDir\baz\zip
c:\1\2\3\MyDir\foo\bar
The target path is relative to the output directory.
When its executed as part of the build it gives an exit code 4
Initialization error occurred. There is not enough memory or disk
space, or you entered an invalid drive name or invalid syntax on the
command line.
Where am I going wrong?

Got it,
I changed the xcopy command in my post build event to:
xcopy "$(TargetDir)*.*" "$(TargetDir)..\..\Foo\Bar\" /s /y /i
The executed result being:
xcopy "c:\1\2\3\MyDir\baz\zip\*.*" "c:\1\2\3\MyDir\baz\zip\..\..\Foo\Bar\" /s /y /i
Which VS2010 much preferred, I guess you can't use a relative path without a base path.

Why you don'y call batch file which will run xcopy for required files source to destination?
call "$(SolutionDir)scripts\copyifnewer.bat"
With copyifnewer.bat looking like this:
IF NOT EXIST <destination> md <destination>
XCOPY /Y <file> <destination>

Related

Stop And Start Windows Service On Build

We want to Stop our windows Service before we rebuild it, Then Build the new version, then Copy it to a specified folder (due to the configuration changes putting the exe in different bin folders). then Restart the windows service. It Sounds Simple but the main problem we're having is stopping the service doesn't immediately release the file locks. Causing the build to fail ever other time. (once to stop the service and once to actually copy and restart it)
Currently as stated we do have a way that works exactly 50% of the time. It is however annoying to have to build twice every time we make a change to the solution. The current way is build events on the project level.
The Prebuild Looks like this:
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
net start | find "ServiceHost"
if Not ERRORLEVEL 1 InstallUtil.exe -u
$(ProjectDir)bin\Current\ServiceHost.exe
Exit /b 0
and the PostBuild Looks Like This:
cd $(ProjectDir)bin
DEL Current\* /F /Q /S
xcopy $(Configuration) Current
cd C:\Windows\Microsoft.NET\Framework\v4.0.30319
InstallUtil.exe $(ProjectDir)bin\Current\ServiceHost.exe
net start ServiceHost
Exit /b 0
There is also the problem of initial creation of the "Current" Folder as our source control doesn't keep the Bin folder. we could add a mkdir current command in there to fix this. if there is a better way to update the service every build your advice would be appreciated.
I have a solution that works. its not ideal but it does seem to work 100% of the time
Prebuild:
net stop ServiceHost
:delete
cd $(ProjectDir)
rmdir /s /q $(ProjectDir)bin\Current
echo delete Error Level %ERRORLEVEL%
goto checkDelete
:checkDelete
cd $(ProjectDir)bin\Current
echo check Error Level %ERRORLEVEL%
if %ERRORLEVEL% == 1 (GOTO end) else (GOTO retry)
:retry
echo Prebuild Retry after 5 seconds
powershell -command "Start-Sleep -s 5"
GOTO delete
:end
echo Prebuild Terminate
Exit /b 0
Post Build:
cd $(ProjectDir)bin
:copy
mkdir Current
xcopy $(Configuration) Current
echo PostBuild Error Level %ERRORLEVEL%
if not %ERRORLEVEL% == 0 (GOTO copy)
echo starting service
net start ServiceHost
Exit /b 0

Create Batch file for iexpress

I am trying to use iexpress to run my batch file which will execute the 2 exe & 1 msi files for me. when i try to do it manually, it works.
following is the code in my batch file.
Start /wait %CD%\1.exe /q
Start /wait %CD%\2.exe /q
msiexec.exe /i "%CD%\3.msi"
but this doesn't seem to be working when i create an exe file from iexpress.
Reference
Above mentioned article has some code(to copy files to temp folder) & but i am not able to understand the syntax.
MKDIR %Tmp%\<UNIQUE PRODUCT NAME>
XCOPY . %Tmp%\<UNIQUE PRODUCT NAME> /S /E /Y
%Tmp%\<UNIQUE PRODUCT NAME>\setup.exe
The problem is that, as you can see from your screenshot, the batch file is being executed by command.com, not cmd.exe. (If you don't specify an interpreter, IExpress uses command.com. Ouch.) So there are no variables like %cd% or %~dp0.
You likely don't need them anyhow. But you do need to execute your batch file explicitly in IExpress like:
cmd.exe /c file.bat
so that it uses a modern command interpreter.
The second bit of code in your question makes the files persistent (ie they won't be deleted after the IExpress archive terminates) by xcopying them to a different directory.
Here is what it means:
1) Creates a directory(MKDIR) with name of "UNIQUE PRODUCT NAME" in the path stored in %TMP% Environment Variable, which normally points to: C:\DOCUME~1\yourusername\LOCALS~1\Temp
MKDIR %Tmp%\<UNIQUE PRODUCT NAME>
2) Then copy recursively all installation files from current folder into the new folder created before.
XCOPY arguments:
/S Copies directories and subdirectories except empty ones.
/E Copies directories and subdirectories, including empty ones.
Same as /S /E. May be used to modify /T.
/Y Suppresses prompting to confirm you want to overwrite an
existing destination file.
XCOPY . %Tmp%\<UNIQUE PRODUCT NAME> /S /E /Y
3) Finally execute the application from the new location
%Tmp%\\setup.exe
Hope this helps
Try replacing %CD% with %~dp0
Assuming that 1.exe is in the same folder as your batch script.
Your %CD% is not working. Please be sure that CMD extensions are enabled (type CMD /x to enable and CMD /y to disable) then expand the %CD% with this code
SET CURDIR=%CD%
Start /wait "%CURDIR%\1.exe" /q
Start /wait "%CURDIR%\2.exe" /q
msiexec.exe /i "%CURDIR%\3.msi"
And I'm not sure that you can start an exe from that location (APPDATA) for security reasons.
Thanks a lot for this forum discussion.Finally i could able to compile all msi files and executables in an one .exe file.
Complete procedure as follows create a batch file
echo on
SET CURDIR=%CD%
msiexec.exe /i "%CURDIR%\1.msi"
"%CURDIR%\3.EXE"
"%CURDIR%\setup.exe"
echo off
You can arrange any number of exe files or msi files as you wish and save the batch file as yourfile.bat.
Now the tricky part is before you proceed to Iexpress, convert the batch file to exe with the software provided by http://www.f2ko.de/programs.php?pid=b2e
Now when you run the program keep the 'Invisible Application' checked to hide the command prompt.You can also encrypt your exe with the password.'Delete at Exit' is optional as the temporary folder will be automatically deleted when the execution of files completed.
Once you successfully compile the batch file,execute the .exe file created.
Bingo!! you'll not see the command prompt window and your applications start executing sequentially.
Begin your Iexpress tool and Add all your files present in the batch file(except batch file).On the ‘Install Program to Launch’ screen, leave the Post Install Command blank and find the following in the Install Program dropdown:'demo.exe'and proceed further to create your complete bunch of single package. Cheers!!

What does this funnelweb command mean in visual studio? and why did it exit with 4?

In visual studio on the post build event command line I have the following:
xcopy $(TargetPath) $(SolutionDir)FunnelWeb.Web\bin\Extensions\ /Y
and its creating the error:
Error 1 The command "xcopy C:\Users\Exitos\Desktop\FunnelWeb-2.0.2.572-source\src\FunnelWeb.Extensions.MetaWeblog\bin\Debug\FunnelWeb.Extensions.MetaWeblog.dll
C:\Users\Exitos\Desktop\FunnelWeb-2.0.2.572-source\src\FunnelWeb.Web\bin\Extensions\
/Y
xcopy C:\Users\Exitos\Desktop\FunnelWeb-2.0.2.572-source\src\FunnelWeb.Extensions.MetaWeblog\bin\Debug\CookComputing.XmlRpcV2.dll
C:\Users\Exitos\Desktop\FunnelWeb-2.0.2.572-source\src\FunnelWeb.Web\bin\Extensions\
/Y" exited with code 4. FunnelWeb.Extensions.MetaWeblog
Im confused as to where the $(TargetPath) and $(SolutionDir) are set, and why this error happened?
xcopy exit codes can be found here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/xcopy.mspx?mfr=true
I suspect the problem is that you need double quotes around your paths:
xcopy "$(TargetPath)" "$(SolutionDir)FunnelWeb.Web\bin\Extensions" /Y
Becouse of spaces inside your path.
When you open a .sln, $(SolutionDir) is the directory where it came from. If you
want to change it, move the root folder for your .sln file.
Hope it helps.

Adding XCopy command through Post Build Event in Visual Studio 2008 for multiple commands

I wanted to add 2 simple XCOPY commands to a post build event for a class file in Visual Studio 2008.
However, Visual Studio doesn't want to run the command unless I've either run the command once from a command line, OR copied the specified files to the target directory first.
Is it possible to specify or suppress/default the /f flag without having to execute the commands first?
xcopy /y "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\TrainingProject\TrainingProject\bin\debug\TrainingProject.dll" "C:\inetpub\wwwroot\slxclient\bin\TrainingProject.dll"
xcopy /y "C:\Documents and Settings\Administrator\My Documents\Visual Studio 2008\Projects\TrainingProject\TrainingProject\bin\debug\TrainingProject.pdb" "C:\inetpub\wwwroot\slxclient\bin\TrainingProject.pdb"
The PDB entry chokes if I have not already copied it manually.
Thanks.
Just don't include the filename in the target path:
if not exist c:\bar\bin md c:\bar\bin
xcopy /y c:\foo\bin\mumble.pdb c:\bar\bin

Xpath error due to miscorrected paths

When i start to debug application i am getting this error Can any one give me the solution
Error 1 The command "xcopy "F:\asoadmin_ML_view\leaf\Console\Bin\Debug\Console.*" "F:\leafPRODUCT\Bin" /f /e /y /i
xcopy "F:\leafPRODUCT..\voyagerhtml\Operations Sentinel Console Help*.chm" "F:\leafPRODUCT\Help" /f /e /y /i
" exited with code 4.
According to this, error code 4 means either you do not have enough memory to perform debugging, or (much more likely) you have invalid syntax. The answer to this thread suggests placing double quotes around your entire path.
Your build process likely has a pre/post build step associated with it that is executing the XCopy commands. Error code 4 implies either insufficient disk space to perform the copy, or a syntax error in the command.
To edit your project's pre/post build steps, right click on your project, then select Properties -> Build Events. To diagnose these commands, try running them from the command line after you build your project.
Maybe the user with which you try to execute the 'xcopy' doesn't have enough permissions (according to this thread: http://social.msdn.microsoft.com/Forums/en-US/tfsbuild/thread/5c4a55e2-243a-427f-800d-39b42c9e860e).

Categories