TFS2015 Builds: Post-build steps fail in Visual Studio Build - visual-studio-2013

I’m having difficulty with vNext builds. Visual Studio Build step.
My solution fails whenever the post build steps in the solution I'm building runs. It exits with code 1.
I think the command I fine, it works fine locally, and on the build server when visual studio is run as an administrator.
I think the build agent doesn’t have permission to write files. Is there any way this can be fixed? Or to have this build step run as administrator?
The post build command is below:
echo POST-BUILD: Building files and copying the components files into host/bin folder
$(ProjectDir)Builder\BuildRules.cmd $(ProjectDir) $(TargetDir) && (IF NOT EXIST $(SolutionDir)..\..\host\Host\bin mkdir $(SolutionDir)..\..\host\Host\bin) && xcopy /F /R /Y $(TargetDir)$(TargetFileName) $(SolutionDir)..\..\host\Host\bin && xcopy /F /R /Y $(TargetDir)Service*Validator1.xsl $(SolutionDir)..\..\host\Host\bin && xcopy /F /R /Y $(TargetDir)Service*Validator2.xsl $(SolutionDir)..\..\host\Host\bin && xcopy /F /R /Y $(TargetDir)Service*Validator3.xsl $(SolutionDir)..\..\host\Host\bin && xcopy /F /R /Y $(TargetDir)Service*Functions.xsl $(SolutionDir)..\..\host\Host\bin && IF "$(BuildUri)"=="" COPY $(SolutionDir)\$(SolutionName)\$(OutDir)\*.xsl $(SolutionDir)\$(SolutionName).UnitTests\bin\$(Configuration)\ /Y
Thank you for any help!

Related

How to copy selected files from one folder to another in Batch file?

In folder C:\A i have afile.h afile.cpp bfile.h bfile.cpp and some other .h and .cpp files (windows 10)
I want to copy only afile.h afile.cpp bfile.h bfile.cpp to C:\B folder and replace them if files in folder A are newer than folder B
I tried below but did not work, bat run but nothing happens
my copybatch.bat file
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
fastddsgen.bat -replace -example CMake aac.idl
xcopy /y /d C:\A\afile.h C:\B
xcopy /y /d C:\A\afile.cpp C:\B
xcopy /y /d C:\A\bfile.h C:\B
xcopy /y /d C:\A\bfile.cpp C:\B
I used call for 2nd command as well
call "C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvarsall.bat" x86_amd64
call fastddsgen.bat -replace -example CMake aac.idl
xcopy /y /d C:\A\afile.h C:\B
xcopy /y /d C:\A\afile.cpp C:\B
xcopy /y /d C:\A\bfile.h C:\B
xcopy /y /d C:\A\bfile.cpp C:\B
Reason to use CALL --> When not using CALL, the current batch file stops and the called batch file starts executing.
What's the meaning of /d in your xcopy command? You might think that you are specifying that the destination is to be a directory, but in fact this is to be used for date related things.
The real problem here might be that your computer does not understand whether C:\B is a directory or a file, causing the problem.
Therefore I'd advise you to follow my answer from this other question, and use the following commands:
xcopy /y C:\A\afile.h C:\B\
xcopy /y C:\A\afile.cpp C:\B\
xcopy /y C:\A\bfile.h C:\B\
xcopy /y C:\A\bfile.cpp C:\B\
Good luck

Post-build event in VS has ceased to work correctly

Hello I developed some plugin for Revit, and after build copy required files in some directory via post-build event. It works for some years but today it has some strange behaviour.
I use such a script
IF NOT "$(ConfigurationName)" == "DEV" (
MD "$(AppData)/Autodesk/ApplicationPlugins/$(ProjectName).bundle/Contents/$(ProjectName)/Resources/Images"
copy /Y "$(ProjectDir)PackageContents.xml" "$(AppData)/Autodesk/ApplicationPlugins/$(ProjectName).bundle"
copy /Y "$(ProjectDir)*.addin" "$(AppData)/Autodesk/ApplicationPlugins/$(ProjectName).bundle/Contents"
xcopy /Y /E /R "$(ProjectDir)Resources/Images/*.png" "$(AppData)/Autodesk/ApplicationPlugins/$(ProjectName).bundle/Contents/$(ProjectName)/Resources/Images"
)
But instead, image files I have this inside Image folder
File-Explorer Screenshot
Also, dlls file not copied.
I create a new solution, and it has some behaviour again.
If you have any idea please help me.
A change post script, and now it work, but i don't know why previos have such behaviour
IF NOT "$(ConfigurationName)" == "DEV" (
MD "$(AppData)/Autodesk/ApplicationPlugins/$(ProjectName).bundle/Contents/$(ProjectName)"
MD "$(AppData)/Autodesk/ApplicationPlugins/$(ProjectName).bundle/Contents/$(ProjectName)/Resources/Images"
copy /Y "$(ProjectDir)/PackageContents.xml" "$(AppData)/Autodesk/ApplicationPlugins/$(ProjectName).bundle"
copy /Y "$(ProjectDir)*.addin" "$(AppData)/Autodesk/ApplicationPlugins/$(ProjectName).bundle/Contents"
xcopy /Y /E /R "$(ProjectDir)bin/$(Configuration)" "$(AppData)/Autodesk/ApplicationPlugins/$(ProjectName).bundle/Contents/$(ProjectName)"
xcopy /Y /E /R "$(ProjectDir)Resources/Images" "$(AppData)/Autodesk/ApplicationPlugins/$(ProjectName).bundle/Contents/$(ProjectName)/Resources/Images"
)

What is the proper way to create a build event with both double quotes and $ in files paths in VisualStudio using cmake

In my project I am trying to copy a directory of files into another directory through the post-build event command in visual studio.
I've come up with this command line code to use in the project xcopy /Y /I /E "$(WorkingDirectory)/abra/kadabra" "$(LocalDebuggerWorkingDirectory)/kadabra"
I would like to auto-generate this command from cmake and from what I understand the
add_custom_command method is what I should be using...
However when I try
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD COMMAND xcopy /Y /I /E "$(WorkingDirectory)/abra/kadabra" "$(LocalDebuggerWorkingDirectory)/kadabra")
I get this as my commandline option in visual studio
setlocal
xcopy /Y /I /E $(WorkingDirectory)/abra/kadabra $(LocalDebuggerWorkingDirectory)/kadabra
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
What am I doing wrong?
I ended up finding an answer, which is basically escaping the quotes. I turned this "$(WorkingDirectory)/abra/kadabra" "$(LocalDebuggerWorkingDirectory)/kadabra") into \"$(WorkingDirectory)/abra/kadabra\" \"$(LocalDebuggerWorkingDirectory)/kadabra\") However, I still get all of the extra setlocal and if %errorlevel% stuff which is not what I wanted. It doesn't however effect my project.

How can I create a Sharepoint package (*.wsp) from command line

I have a number of SharePoint web part projects in a single solution. To deploy a web part, I am using the "Publish..." option from solution explorer in visual studio. Then use the stsadm.exe to deploy them on SharePoint server.
Is it possible to generate a *.wsp package from the command line?
You can use msbuild tool to generate wsp packages.
Below you can find example of cmd script:
set msbuild="C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
set config=Release
set outdir2=C:\out\
rd /S /Q "%outdir2%"
%msbuild% /p:Configuration=%config% /m "C:\Test\test.csproj" /t:Package /p:BasePackagePath=%outdir2%
for /F "tokens=*" %%i in ('dir /B /S "%outdir2%"') do if not %%~xi == .wsp del %%i

How to use xcopy to only copy files if they are newer?

I have many web applications in a Visual Studio solution.
All have the same post build command:
xcopy "$(TargetDir)*.dll" "D:\Project\bin" /i /d /y
It would be useful to avoid replacing newer files with old ones (e.g. someone could accidentally add a reference to an old version of a DLL).
How can I use xcopy to replace old files only with newer DLL files generated by Visual Studio?
From typing "help xcopy" at the command line:
/D:m-d-y Copies files changed on or after the specified date.
If no date is given, copies only those files whose
source time is newer than the destination time.
So you already are using xcopy to only replace old files with new ones. If that's not happening, you may have to swap the positions of the /i and /d switches.
User following command to copy all new and modified file from source to destination
xcopy c:\source d:\destination /D /I /E /Y
/D to check any modified file are there
/I If the destination does not exist and copying more than one file, assumes that destination must be a directory.
/E To copy directory and sub directories
/Y to suppress any over write prompt.
Not tested, but I use a similar command script for these sorts of tasks.
set DIR_DEST=D:\Project\bin
pushd "$(TargetDir)"
::
:: Move Files matching pattern and delete them
::
for %%g in (*.dll) do (xcopy "%%g" "%DIR_DEST%" /D /Y & del "%%g")
::
:: Move Files matching pattern
::
:: for %%g in (*.dll) do (xcopy "%%g" "%DIR_DEST%" /D /Y )
popd

Resources