VisualStudion 2012: Post build Events - visual-studio-2012

In my project I have got following post-build Event:
xcopy "$(TargetDir)Data" "$(ProjectDir)Data" /Y /I
After the run has ended the program copies the files. But if in TargetDir/Data is a complete NEW file, this event does not copy the new file to ProjectDir/Data.
but I would like to have this new files copied to TargetDir/Data. How do I achieve this?
Thanks for help!

"Data" sounds like a directory, not a file. You'll have to create it first. You also appear to have reversed the arguments. Fix:
if not exist "$(TargetDir)Data" mkdir "$(TargetDir)Data".
xcopy "$(ProjectDir)Data\*.*" "$(TargetDir)Data" /Y /I /D
If you in fact meant to copy back to the project directory, very unusual, then just swap TargetDir and ProjectDir in the above snippet.

Related

How do I delete node_modules folder quickly?

When I want to delete a node_modules folder it takes ages when I delete it using Windows Explorer. How do I delete faster?
I use to have the same issue, taking hours to achieve the deletion until I found this workaround:
Select the node_modules folder. Do this with the file explorer.
Open Powershell as admin: press Alt+F, then S, then A.
Wait and accept to open Powershell as admin
Paste this command and press Enter: del /f/q/s *.* > nul.
WARNING
Please be sure to be in the folder node_modules. I mean, that the terminal path ends with ...\node_modules.
In the above command, we use the /f switch to force the deletion of read-only files. The /q switch enables quiet mode. The /s switch executes the command for all files in any folder inside the folder you’re trying to remove. Using *.* tells the del command to delete every file and > nul disables the console output improving performance and speed.
Wait for the process to take action.
Now go up one level in the directory with cd...
Finally use this command to delete the node_modules folder rmdir /q/s node_modules
In the above command, we use the /q switch to enable quiet mode, the /s switch to run the command on all the folders, and node_modules is the variable you need to specify to delete the folder you want.
If you get an error with Powershell try other terminals as administrator like Windows Terminal, Command Prompt (cmd) or third party terminals like ConEmu. I made this steps with Cmder and all the deletion was done in just 5 minutes. Off course this duration is variable according to the size of the folder.
References:
pureinfotech.com
ConEmu
Cmder
From you project folder use following command to delete it:
rd .\node_modules\ /s /q

Windows 'move' command's /y not overriding destiation file, failing with an error: file already exists

In wine and wineconsole when I try and move a file with the following command:
move /Y "file" "destination" I get the following error:
File already exists
and the file is not replaced. According to the windows help page http://technet.microsoft.com/en-us/library/bb490935.aspx /y should suppress the prompt asking if you wish to override the file, which it does, and also overwrite the file, which it fails at.
If I don't use /y it prompts me, after responding yes the file is overwritten. Can someone confirm the move command with /y is broken in wine (v1.6) and if so offer any suggestions while still using the move command.
As a temporary fix I perform a del /f/q on the destination before I move the file.

The command xcopy ... exited with code 9009 in Visual Studio

When I build my solution with 10 Projects I get Build failures for 7 projects. All 10 Projects have post-build events. Even those who build use an xcopy command. I say this because my colleague was the opinion VS 2012 and xcopy is not that good...
These 7 build failures did not happen before.
The following error happens when I try to build the project or "from time to time" when I start my Visual Studio.
I get this error:
Error 1 The command "xcopy /y "D:\Replaced\branches\ReplacedTest\Swan.Replaced.Mobile.Web\Client" "D:\Replaced\branches\ReplacedTest\build\web\bin\..\Client\" /s /e /v
xcopy /y "D:\Replaced\branches\ReplacedTest\Swan.Replaced.Mobile.Web\Content" "D:\Replaced\branches\ReplacedTest\build\web\bin\..\Content\" /s /e /v
xcopy /y "D:\Replaced\branches\ReplacedTest\Swan.Replaced.Mobile.Web\Views" "D:\Replaced\branches\ReplacedTest\build\web\bin\..\Views\" /s /e /v
xcopy /y "D:\Replaced\branches\ReplacedTest\Swan.Replaced.Mobile.Web\web.config" "D:\Replaced\branches\ReplacedTest\build\web\bin\..\"
xcopy /y "D:\Replaced\branches\ReplacedTest\Swan.Replaced.Mobile.Web\global.asax" "D:\Replaced\branches\ReplacedTest\build\web\bin\..\"
xcopy /y "D:\Replaced\branches\ReplacedTest\Swan.Replaced.Mobile.Web\Tools" "D:\Replaced\branches\ReplacedTest\build\web\bin\..\..\Tools\" /s /e /v
" exited with code 9009. Swan.Replaced.Mobile.Web
I have googled a lot on SO and the main cause for this problem seem to be:
1.) A whitespace in the path/folder name
2.) The command does not get full paths
3.) Maybe some environment/system variables problem?
I can not see this error in my post-build event:
xcopy /y "$(ProjectDir)Client" "$(TargetDir)..\Client\" /s /e /v
xcopy /y "$(ProjectDir)Content" "$(TargetDir)..\Content\" /s /e /v
xcopy /y "$(ProjectDir)Views" "$(TargetDir)..\Views\" /s /e /v
xcopy /y "$(ProjectDir)web.config" "$(TargetDir)..\"
xcopy /y "$(ProjectDir)global.asax" "$(TargetDir)..\"
xcopy /y "$(ProjectDir)Tools" "$(TargetDir)..\..\Tools\" /s /e /v
My TargetDir is this outputpath:
..\build\web\bin\
My ProjectDir is this:
D:\Replaced\branches\ReplacedTest
comment: When I use xcopy on the console window thats totally fine.
These are my specs:
Windows 7 (64bit)
Visual Studio 2012 Premium
What I have tried to fix the issue:
Rebuild solution
Clean solution
wipe outputpath data
reboot computer
bite in the desktop
Nothing helped :/
Anyone can help please to spot the error? Thanks!
xcopy is usually located in C:\Windows\system32 so in order for VS to see xcopy this path should be in your PATH environment variable. You can check this by running:
echo %path%
in command line and you should see path to xcopy alongside other folders...
I just added C:\Windows\System32\ in front of the xcopy command and it solved things. In mean time also check that you didn't at some additional line breaks on accident. But if you like, you can also add the system directory back to your windows path. You can find this at computer - properties - advanced system settings - environment variables - system variables - path.
So for example:
C:\Windows\System32\xcopy /s /y "$(ProjectDir)bin\ken.MojoPortal.HtmlTools.Web.dll" "$(SolutionDir)Web\bin\"
P.S Originally posted here : https://ict.ken.be/xcopy-exit-with-code-9009-in-visual-studio-post-build

Command Line Batch Script

i use this script to compress all .txt and .cpi files into the backup folder in separated files with 7zip. After the files are zipped i delete the original files. However this script has a logical flaw. Lets say if the 7zip program fails to run, the files will also get deleted. How can i change the script so that it should not delete the files if they don't get zipped first. Also how can i change this script so it zips files that are older than 7 days? Thanks for your help.
#echo off
setlocal
set _source=C:\test7zip\bak
set _dest=C:\test7zip\bak
set _wrpath=C:\Program Files\7-Zip
if NOT EXIST %_dest% md %_dest%
for %%I in (%_source%\*.txt,%_source%\*.cpi) do "%_wrpath%\7z" a "%_dest%\%%~nI.7z" "%%I" & del "%%I"
pause
You seem to now more than me but i might be able to help....
Inside the 7zip you could a batch file that when unzipped changes a system varible...
The batch file (that you have already done) that unzips the files could check to see if variable is true before delete the files .... or something.?
Hope that helps in anyway?
For the zipping of the files witch are a certain days old... you could have a batch file that has a 7 day timer and that after the time is up it zips the certain directory of files into 7zip?
That's all i could help you with.
I didn't check or test your code thoroughly, but I did notice this right away. The "&" in the last line of your script creates a conditional command that will always execute the second command, regardless whether the 1st fails or succeeds. Change it to && to create a conditional command where the 2nd command only executes upon successful completion of the 1st, like this:
for %%I in (%_source%*.txt,%_source%*.cpi) do "%_wrpath%\7z" a "%_dest%\%%~nI.7z" "%%I" && del "%%I"
For including files older than 7 days, use the below changes to move them to a temp directory before zipping them:
set _source=C:\test7zip\bak
set _dest=C:\test7zip\bak
set _temp1=C:\test7zip\temp1
set _wrpath=C:\Program Files\7-Zip
if NOT EXIST %_dest% md %_dest%
forfiles /P %_source% /S /M *.txt /D -7 /C "cmd /c move #file %_temp1%"
forfiles /P %_source% /S /M *.cpi /D -7 /C "cmd /c move #file %_temp1%"
for %%I in (%_temp1%\*.txt,%_temp1%\*.cpi) do "%_wrpath%\7z" a "%_dest%\%%~nI.7z" "%%I" && del "%%I"

Zip batch command and Excel

I have many excel files that I need zipped into each of their own zip folders. I thought I had this ironed out, but I have co-workers coming back to me saying that they cannot open the excel file because it has become corrupted. I went back and checked the original file, and it opens up just fine. But when I open up the same version of the file that was zipped, I too get the corrupted error. I'm on Office 2010, which is able to repair it, but my co-workers are all Office 2007 which does not seem to be able to fix the file. My batch code is as follows:
for /r %%X in (*.xlsm) do "C:\Program Files\7-Zip\7z.exe" a -tzip "%%~nX" "%%X"
I think you might be using a wrong value as the first parameter to the 7zip executable. According to the documentation on FOR:
%~nI - expands %I to a file name only
And according to the 7zip documentation:
You can use the "a" command with the single letter a. This command stands for 'archive' or 'add'. Use it to put files in an archive. You have to specify the destination archive, and the source files (in that order).
So, using your script with an example file, it seems to me that your command line becomes:
"C:\Program Files\7-Zip\7z.exe" a -tzip "somefile.xlsm" "C:\path\to\somefile.xlsm"
Shouldn't the first parameter have a .zip file extension on the end? So the line is modified to look like this:
for /r %%X in (*.xlsm) do "C:\Program Files\7-Zip\7z.exe" a -tzip "%%~nX.zip" "%%X"
As annoying as it is, file extensions actually mean something in Windows. Your previous line was creating a zip file with the .xlsm extension. When people try opening those files, Excel complains (because it's a zip file; not a .xlsm).
#Echo OFF
PUSHD "C:\Program Files\7-Zip" && (
FOR /R "%CD%" %%# in (*.xlms) DO (7z a -tzip "%%~n#.zip" "%%#")
POPD
)
REM Don't worry about the PUSHD command, the %CD% variable isn't expanded, that's the trick.
Pause&Exit
And you can use the dynamic operator * (asterisk) and 7zip -recursive parameter if you want all together in one file:
7z a -r -tzip "ALL.zip" "*.xlsm"
Sorry guys.
It was a false alarm. Turns out it wasn't all of the files, but only a select few. The files were sectioned out by region, and the only ones that were corrupt were the first region. Why? I can only assume that they were corrupted by my original attempts at making a batch file, as all the other files were zipped with the finished batch and thus didn't have errors. So nothing was wrong with my script. Thanks for the help though.

Resources