$(SolutionDir) in MS VisualStudio Build events - visual-studio

XCOPY /Y /E "$(SolutionDir)CopyOnBuild\*.*" ".\"
is the command right now. Which tell that the directory to copy files is at same level where the sln is.
My Question is: I want to copy the files to a directory which is one level above the solution directory. How the command should be?

If you are trying to change the destination dir, and make it one level up, try putting two dots instead of one:
XCOPY /Y /E "$(SolutionDir)CopyOnBuild\*.*" "..\"

Related

Windows xcopy 0 File(s) copied

I am trying to copy a directory but get the following:
xcopy ..\node_modules\ \node_modules\
0 File(s) copied
I run as administrator, but still get the error. Any ideas please?
p.s I actually use the following to stipulate it's a directory. But the above also fails:
echo d | xcopy /d /y ..\node_modules\ \node_modules\
Thanks
You can use the xcopy /E flag to copy the entire directory and subdirectories. Also remove the starting \ of the destination. The trailing slash should prevent the file or directory prompt.
xcopy /E ..\node_modules node_modules\
xcopy ..\node_modules\* \node_modules\
You are specifying the source directory, but not which files to copy.
To copy all the contents like folder, sub-folder or chain of folders we can use below command:
xcopy file-to-copy-path\ where-to-copy-path\ /s /i
/s copies folders and sub-folders
/i If in doubt always assume the destination is a folder e.g. when the destination does not exist.

Copy Directory files to another directory in batch file without asking?

I have created a batch file to copy one folders files to another folder.
This code XCOPY C:\Temp\a.txt C:\Temp2\a.txt /Q works but when i run this file it ask Overwrite C:\Temp2\a.txt (Yes/No/All)?
I want to do this without asking this question. How can i do ? And i want to this for aspx or aspx.cs files
From the manual:
/Y Suppresses prompting to confirm you want to overwrite an existing
destination file
So just add the /Y option in order to overwrite all files without asking.
If you want to copy all files that contain "aspx", you can use
XCOPY C:\Temp\aspx* C:\Temp2\ /Q /Y
You can try this :
XCOPY C:\Temp\a.txt C:\Temp2\a.txt /Q /Y

Delete files do not exist in source folder in cmd?

I have two folders that I backup from source to destination folder using command:
xcopy /E /Y /I /D
Now I want to delete files in destination folder that do not exist in source folder.
There is no 'mirroring' option in xcopy. I have 2 suggestions:
1.
you could run xcopy dest source /L > todelete.txt to obtain a list of files which exist in dest but not in source. Then use a for loop to delete these files in dest.
or
2.
Use robocopy which was designed to use the same options as xcopy but has a lot more funtionality. For instance, a /MIR option to mirror one folder to the other. robocopy is included in all Windows versions from Vista on (the Win7 version might run under XP as well - not tested though).
Besides, it is way faster and and and...

Copying folders on post build in Visual Studio

Lets say I have a project solution, I want to copy the contents of bin/Release folder after the build into another folder named "Deploy"
Source: D:\Solution\bin\Release
Destination: D:\Destinationfolder\bin\deploy
the macros are as follows
TargetDir : D:\Solution\bin\Release
ProjectDir: D:\Solution
I have tried this
xcopy /? $(TargetDir) $(ProjectDir)\..\Bin\Deploy /R /Y /S
This is not working. Am I doing anything wrong? Is there any other way to do this?
Remove the /? from the xcopy command, and add quotes around paths. The .. will take the $(ProjectDir) path back to D:, so the Destinationfolder should also be added.
So: xcopy "$(TargetDir)" "$(ProjectDir)\..\Destinationfolder\Bin\Deploy" /R /Y /S
I would suggest you to create a Publish Profile. If you want to build the project to a desired folder you can simply right click on the project and click Publish.

Windows cmd shell xcopy to network directory doesn't work

Im trying to make a batch file that will copy all new files and folders from a source folder to an network directory. All the new subdirectories and new files should be copied (backup).
My code:
xcopy "C:\Source" "T:\Backup" /d/i/s/q
(/d for only new files, /i because source is a dir, /s for all the subdirs and files, /q just to supress the copy text)
Source contains both subdirectories and files (.txt).
The first run it copies Everything as it should. When I add a new .txt file to one of the existing subdirectories and run it again I get the message:
"An error occured when the file The directory is not empty. was being created.
The folder "T:\Backup" could not be created.
0 files copied.
(Translated from Swedish so not 100% original)
The thing is when I try this command to a local source like e.g. "C:\test" and do the same procedure it works.
Anyone who can understand why this doesn't work for the network drive?
Should I try Another command such as robocopy?
Skip xcopy and use robocopy with the /E flag instead. It's built into all recent versions of Windows. Free download for XP.
Example:
robocopy c:\source T:\backup /E
That will copy all the files in the "source" folder to the "backup" folder that haven't been copied already.
And if you don't want to have the output shown on the console (equivalent to the /Q option in xcopy):
robocopy c:\source T:\backup /E /LOG:nul
Robocopy must be better because it should create directories with the \E switch. No overwrites for files, just adds a file with extra letters or extension <> command. Still must defrag.
XCOPY "DRIVE LETTER:\windows.old\USERS" "\computername\D\NAME\" /D /E /C /R /I /K /Y /f

Resources