I have a VS 12 solution with my own project, which depends on some dependencies (project files generated using cmake). I generated these VS12 projects using cmake and added these projects to my solution (using a relative path). Then I had to adjust the output directories of these projects, to build the target somewhere else where my own project can find them (so just running cmake again after the path changes doesn't solve my problem, because I would have to edit all projects again then).
If now the absolute path for the solution changes, the solution can still find the projects - but at building I receive errors from cmake, that the "old path" didn't exists.
Steps to reproduce my problem:
Download the cmake Project from here.
Extract into a Directory on C:\cmake
Create inside a Directory called C:\cmake\build
Open a command-line and go to C:\cmake\build
execute cmake ..
rename the C:\cmake Directory to C:\cmake2
Open the solution C:\cmake2\build\CMake.sln
There will occur a long list with errors (too long to include here completly) - all caused because the old path "C:\cmake\" ist still used from somewhere. An example:
1>------ Build started: Project: ZERO_CHECK, Configuration: Debug Win32 ------
2>------ Skipped Build: Project: RUN_TESTS, Configuration: Debug Win32 ------
2>Project not selected to build for this solution configuration
1> Checking Build System
1> CMake is re-running because C:/cmake/build/CMakeFiles/generate.stamp dependency file is missing.
1>CUSTOMBUILD : CMake error : The source directory "C:/cmake" does not appear to contain CMakeLists.txt.
1> Specify --help for usage, or press the help button on the CMake GUI.
3>------ Build started: Project: cmbzip2, Configuration: Debug Win32 ------
4>------ Build started: Project: cmzlib, Configuration: Debug Win32 ------
5>------ Build started: Project: cmexpat, Configuration: Debug Win32 ------
6>------ Build started: Project: cmsys, Configuration: Debug Win32 ------
3>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.Targets(1422,5): warning : The referenced project 'C:/cmake/build/ZERO_CHECK.vcxproj' does not exist.
I want to generate VS Project files just one time - not again, if the Location of the folder changes. Any ideas how cmake can make use of relative paths instead?
Even that the question is downvoted I will provide an answer here for people that are facing the same problem (and depending on their environment it can be real a problem in my opinion).
I removed from all project files that are referenced from my solution at least the following part:
<ItemGroup>
<CustomBuild Include="..\..\Source\CMakeLists.txt">
<Message Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Building Custom Rule C:/cmake/Source/CMakeLists.txt</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">setlocal
"C:\Program Files\CMake 2.8\bin\cmake.exe" -HC:/cmake -BC:/cmake/build --check-stamp-file C:\cmake\build\Source\CMakeFiles\generate.stamp
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">C:/cmake/Source/CMakeLists.txt;C:\cmake\Source\CMakeLists.txt;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.cmake;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.c.in;C:\cmake\Source\cmConfigure.cmake.h.in;C:\cmake\Source\cmVersionConfig.h.in;C:\cmake\Source\CPack\cmCPackConfigure.h.in;C:\cmake\Source\CMakeLists.txt;%(AdditionalInputs)</AdditionalInputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">C:\cmake\build\Source\CMakeFiles\generate.stamp</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</LinkObjects>
<Message Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Building Custom Rule C:/cmake/Source/CMakeLists.txt</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">setlocal
"C:\Program Files\CMake 2.8\bin\cmake.exe" -HC:/cmake -BC:/cmake/build --check-stamp-file C:\cmake\build\Source\CMakeFiles\generate.stamp
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">C:/cmake/Source/CMakeLists.txt;C:\cmake\Source\CMakeLists.txt;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.cmake;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.c.in;C:\cmake\Source\cmConfigure.cmake.h.in;C:\cmake\Source\cmVersionConfig.h.in;C:\cmake\Source\CPack\cmCPackConfigure.h.in;C:\cmake\Source\CMakeLists.txt;%(AdditionalInputs)</AdditionalInputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">C:\cmake\build\Source\CMakeFiles\generate.stamp</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">false</LinkObjects>
<Message Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">Building Custom Rule C:/cmake/Source/CMakeLists.txt</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">setlocal
"C:\Program Files\CMake 2.8\bin\cmake.exe" -HC:/cmake -BC:/cmake/build --check-stamp-file C:\cmake\build\Source\CMakeFiles\generate.stamp
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">C:/cmake/Source/CMakeLists.txt;C:\cmake\Source\CMakeLists.txt;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.cmake;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.c.in;C:\cmake\Source\cmConfigure.cmake.h.in;C:\cmake\Source\cmVersionConfig.h.in;C:\cmake\Source\CPack\cmCPackConfigure.h.in;C:\cmake\Source\CMakeLists.txt;%(AdditionalInputs)</AdditionalInputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">C:\cmake\build\Source\CMakeFiles\generate.stamp</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='MinSizeRel|Win32'">false</LinkObjects>
<Message Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">Building Custom Rule C:/cmake/Source/CMakeLists.txt</Message>
<Command Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">setlocal
"C:\Program Files\CMake 2.8\bin\cmake.exe" -HC:/cmake -BC:/cmake/build --check-stamp-file C:\cmake\build\Source\CMakeFiles\generate.stamp
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd</Command>
<AdditionalInputs Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">C:/cmake/Source/CMakeLists.txt;C:\cmake\Source\CMakeLists.txt;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.cmake;C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\CheckIncludeFile.c.in;C:\cmake\Source\cmConfigure.cmake.h.in;C:\cmake\Source\cmVersionConfig.h.in;C:\cmake\Source\CPack\cmCPackConfigure.h.in;C:\cmake\Source\CMakeLists.txt;%(AdditionalInputs)</AdditionalInputs>
<Outputs Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">C:\cmake\build\Source\CMakeFiles\generate.stamp</Outputs>
<LinkObjects Condition="'$(Configuration)|$(Platform)'=='RelWithDebInfo|Win32'">false</LinkObjects>
</CustomBuild>
</ItemGroup>
And:
<ItemGroup>
<ProjectReference Include="C:/cmake/build/ZERO_CHECK.vcxproj">
<Project>FE0DC35D-28F6-4786-A563-DFE14862A57F</Project>
</ProjectReference>
</ItemGroup>
That prevents the behaviour that CMakeLists.txt is checked for changes before each build. If all other paths in the project file are relative the cmake project is free moveable on the harddisk now.
The Problem with this custom build step is: It isn't displayed in Visual Studios Project Settings, so the plain .vcxproj must be edited manually.
Related
Am trying to run dotfuscator via an Exec task using MSBuild. It gives a msb3073 exited with code 1 , any ideas or suggestions on further troubleshooting appreciated.
Following is the command in the target file:
<Target>
<Exec Command="%22$(ObfuscatorExe)%22 /q /p=AppPath=%22$(TargetDir.TrimEnd('\'))%22,ObfuscatedDll=%22$(TargetFileName)%22,PackageDir=%22$(ModuleDir)%22 %22$(PathOfDotFuscatorXml)%22" />
</Target>
The command gets translated as below.
error MSB3073: The command ""C:\Program Files (x86)\PreEmptive Solutions\Dotfuscator Professional Edition Evaluation 4.35.0\dotfuscator.exe" /q /p=PluginPath="<dlloutputpath>",ObfuscatedDll="<dllname>",PackageDir="<packageDir>" "<path to dotfuscator.xml>"" exited with code 1.
I have a feeling the extra quotes at the start and the end is causing this problem , because if i try to run this command on the dotfuscator command line , i am able to get the command working.
Additionally the MSBuild build output is set to diagnostic.
In my "plange_superbuild" CMakeLists.txt, I have:
add_test(plange_test ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/prefix/src/plange-build --target test)
which should invoke the "plange" sub-project's test target, and works fine when using the Makefile generator. However, the CMake Testing documentation explains:
[ enable_testing() ] adds another build target, which is test for Makefile generators,
or RUN_TESTS for integrated development environments (like Visual
Studio).
So, my snippet doesn't work on builds with an IDE because I'm just saying "test". How can I make the command also work in IDE builds?
I've thought of some possible workaround options. One is to use an existing CMake variable, should it exist, to get the name of the test target. That is a variable (lets call it CMAKE_TEST_TARGET) that would be equal to test except in IDE builds where it would be equal to RUN_TESTS, allowing the following:
add_test(plange_test ${CMAKE_COMMAND} --build ${CMAKE_BINARY_DIR}/prefix/src/plange-build --target ${CMAKE_TEST_TARGET})
I'm not aware of such a variable though. Perhaps I could detect IDE based builds via the CMAKE_GENERATOR variable (or MSVC and similar) and manually set the so-called CMAKE_TEST_TARGET variable. That would require knowing (and maintaining) the exact logic that CMake uses to determine "test" or "RUN_TESTS" in my CMakeLists.txt, which would be unreliable.
My other thought is to invoke ctest directly using a variable (let's call is CTEST_COMMAND) that's similar to CMAKE_COMMAND, but points to the ctest executable. Again, I'm not aware of such a variable.
Edit: There is CMAKE_CTEST_COMMAND See https://stackoverflow.com/a/736838/395029 and my comment therein
I derived this variable from CMAKE_COMMAND, using get_filename_component() to extract the bin directory, but this depends on CMAKE_COMMAND not having any embedded arguments. Is that a safe assumption? This works with the Makefile generator, but not with VC++2017 generator. The error message in VC++ is not clear, but here's what I tried:
get_filename_component(CMAKE_EXECUTABLES_DIR ${CMAKE_COMMAND} DIRECTORY)
set(CTEST_COMMAND "${CMAKE_EXECUTABLES_DIR}/ctest${CMAKE_EXECUTABLE_SUFFIX}")
add_test(NAME plange_test COMMAND ${CTEST_COMMAND} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/prefix/src/plange-build)
The error message in VC++2017 in the superbuild project:
1>The following tests FAILED:
1> 1 - plange_test (Failed)
1>Errors while running CTest
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,5): error MSB3073: The command "setlocal
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,5): error MSB3073: "C:\Program Files\CMake\bin\ctest.exe" --force-new-ctest-process -C Debug
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,5): error MSB3073: :cmEnd
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,5): error MSB3073: :cmErrorLevel
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,5): error MSB3073: exit /b %1
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,5): error MSB3073: :cmDone
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd
1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppCommon.targets(133,5): error MSB3073: :VCEnd" exited with code 8.
1>Done building project "RUN_TESTS.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 1 up-to-date, 0 skipped ==========
I was able to run the command from that error output successully:
C:\...\plange.build\prefix\src\plange-build>ctest --force-new-ctest-process -C Debug
but:
C:\...\plange.build>ctest --force-new-ctest-process -C Debug
fails, so that makes the failure even more confusing. Are one of these common practice? Is there some superior (working) approach that I haven't considered?
Edit: with CMAKE_CTEST_COMMAND I learned that "-C Debug" isn't passed, which makes it fail in IDE. See my comments
In cmake source you can find a variable that is undocummented but may serve your purpose if you are using include(CTest) instead of enable_testing()
Check out this commit: https://github.com/Kitware/CMake/commit/816c9d1aa1f2b42d40c81a991b68c96eb12b6d26#diff-73eaa76f278a4e8afe41a9ffb838ccc4:
# If requested, add an alias that is the equivalent of the built-in "test"
# or "RUN_TESTS" target:
if(CTEST_TEST_TARGET_ALIAS)
add_custom_target(${CTEST_TEST_TARGET_ALIAS}
${CMAKE_CTEST_COMMAND} ${__conf_types}
USES_TERMINAL
)
endif()
endif()
Meaning that if in your Cmakelist.txt you call set(CTEST_TEST_TARGET_ALIAS my_name_for_target_test) and then include(CTest), you can use reliably the my_name_for_target_test acording to this comment (I did not check myself if this really does the trick). Since this alias is created via add_custom_target, this is not a builtins target and you dont have the (really annoying) limitations of thoses, including not being able to add a dependency on it / from it.
I have successfully built VTK 7.1.1 and Qt 5.3.2 with MSVC2013. I have downloaded GCDM and configured with Cmake with no shared_lib. I can build the ALL_BUILD project in GDCM solution configured with CMake, but the INSTALL project can not be built and it gives me this error:
1>------ Build started: Project: vtkgdcm, Configuration: Debug x64 ------
1> vtkImageMapToColors16.cxx
1>c:\vtk\gdcm-2.6.7\utilities\vtk\vtkImageMapToColors16.h(116): error C2555: 'vtkImageMapToColors16::GetMTime': overriding virtual function return type differs and is not covariant from 'vtkObject::GetMTime'
1> C:\VTK\VTK-7.1.1\Common\Core\vtkObject.h(107) : see declaration of 'vtkObject::GetMTime'
2>------ Build started: Project: INSTALL, Configuration: Debug x64 ------
2> -- Install configuration: "Debug"
2> CMake Error at cmake_install.cmake:31 (file):
2> file INSTALL cannot find "C:/VTK/bin/../../../bin/vtkCommonCore-7.1.dll".
2>
2>
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: The command "setlocal
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: "C:\Program Files\CMake\bin\cmake.exe" -DBUILD_TYPE=Debug -P cmake_install.cmake
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: if %errorlevel% neq 0 goto :cmEnd
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: :cmEnd
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: :cmErrorLevel
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: exit /b %1
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: :cmDone
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: if %errorlevel% neq 0 goto :VCEnd
2>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(132,5): error MSB3073: :VCEnd" exited with code 1.
========== Build: 0 succeeded, 2 failed, 17 up-to-date, 0 skipped ==========
It says it can not find vtkCommonCore-7.1.dll ,and that file does not exist on my vtk, but the .lib version of the file exists.
Can anybody save me?
I solved my problem this way:
First, I built the .dll missing files by building VTK using shared_libs option ON.
Secondly, as Jamey mentioned I fixed the error C2555 by changing the definition of GetMTime in vtkImageMapToColors16, apparently VTK version 7.1.1 was not compatible with GDCM 2.6. So I changed the output type of GetMTime function from long int to output of the virtual function in vtkObject::GetMTime.
I am trying to build an opensource project on my machine using Visual Studio 2015 and CMake. I have followed all the steps and the prebuild checks were running properly. But when I am building the INSTALL to install the software in the folder that I have specified in the CMAKE gui, I am getting the MSB3073 error. A full description of the error is as below.
Severity Code Description Project File Line Suppression State Error
MSB3073 The command "setlocal
"C:\Program Files (x86)\CMake\bin\cmake.exe" -DBUILD_TYPE=RelWithDebInfo -P cmake_install.cmake
if %errorlevel% neq 0 goto :cmEnd
:cmEnd
endlocal & call :cmErrorLevel %errorlevel% & goto :cmDone
:cmErrorLevel
exit /b %1
:cmDone
if %errorlevel% neq 0 goto :VCEnd
:VCEnd" exited with code 1.
INSTALL C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets 133
I have searched for the same error and found that some people who tried to install the build in a directory without write privileges encountered this, but I have made sure that I have write access. I have even tried do this with admin rights and still not able to fix this issue.
Any help in this would be highly appreciated.
While running Visual Studio 2022, trying to build VST plug-in with code generated by cmake.
For me it showed permission access denied when creating a symbolic link.
All I had to do was run Visual Studio "As Administrator" and it worked.
Of course, you have to have Admin privileges to your machine, or you belong to a group that is allowed to "Create symbolic links" in the Local Group Policy Editor (https://developer.steinberg.help/display/VST/Preparation+on+Windows)
Sorry for being a necro but I just encountered and fixed the exact same issue, and I think it can save someone some time if I share my solution.
By looking a bit in the log before the error message, I found the last element that CMake was trying to install :
-- Installing: path-to-anaconda/anaconda3/Lib/site-packages/cv2.cp37-win_amd64.pyd
CMake Error at modules/python3/cmake_install.cmake:45 (file):
file INSTALL cannot copy file
"path-to-repo/opencv/build/lib/python3/Release/cv2.cp37-win_amd64.pyd" to
"path-to-anaconda/anaconda3/Lib/site-packages/cv2.cp37-win_amd64.pyd":
Permission denied.
Call Stack (most recent call first):
modules/cmake_install.cmake:183 (include)
cmake_install.cmake:124 (include)
Permission denied...
It was simply because I left a console with cv2 imported, so the pyd was still being used and blocked the install. This can probably extend to any other file (DLLs, .hpp) being installed, just look a bit above this obscure error message ! Nothing to do with cmake_install.cmake, at least for me.
There was an error in one of the cmake_install.cmake files and it was causing the issue. Once I fixed the issue, it worked.
This is my first dive into MSBuild so I'm feeling pretty lost.
The end goal is to run an executable which will output a file, and we want the output of the build to be that file. In this build there is no VS project what so ever.
The build is being run by TFS build services.
At this point all I'm trying to do is generate a file and have it copied to the drop folder.
Here is the contents of my .proj file
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Message Text="Output Dir: $(OutDir)" />
<MakeDir Directories="$(OutDir)" />
<Exec Command='dir /s > \\ANetworkPath\dir.txt
dir /s > $(OutDir)Dir2.txt'/>
</Target>
</Project>
The first command of writing dir to the network path succeeds, however it doesn't show the existence of $(OutDir). So I thought I would try to create it with MakeDir. When the second dir command executes it errors because the path doesn't exist.
TFS is running MSBuild with the following command
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe /nologo /noconsolelogger "C:\Builds\1\Scratch\Test Build\Sources\user\Test\Build.proj" /m:1 /fl /p:SkipInvalidConfigurations=true /p:OutDir="C:\Builds\1\Scratch\Test Build\Binaries\\" /p:VCBuildOverride="C:\Builds\1\Scratch\Test Build\Sources\user\Test\Build.proj.vsprops" /dl:WorkflowCentralLogger,"C:\Program Files\Microsoft Team Foundation Server 2010\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;BuildUri=vstfs:///Build/Build/111;InformationNodeId=6570;TargetsNotLogged=GetNativeManifest,GetCopyToOutputDirectoryItems,GetTargetPath;TFSUrl=http://tfshost:8080/tfs/Test%20Collection;"*WorkflowForwardingLogger,"C:\Program Files\Microsoft Team Foundation Server 2010\Tools\Microsoft.TeamFoundation.Build.Server.Logger.dll";"Verbosity=Normal;"
The only output is in the file written on the network:
Directory of C:\Builds\1\Scratch\Test Build\Sources\user\Test
09/17/2010 10:53 AM <DIR> .
09/17/2010 10:53 AM <DIR> ..
09/17/2010 10:53 AM <DIR> A Directory
09/17/2010 10:53 AM 0 Test.log
09/17/2010 10:53 AM 453 Test.proj
09/17/2010 10:53 AM 201 Test.proj.vsprops
3 File(s) 654 bytes
Directory of C:\Builds\1\Scratch\Test Build\Sources\user\Test\A Directory
09/17/2010 10:53 AM <DIR> .
09/17/2010 10:53 AM <DIR> ..
09/17/2010 10:53 AM 9 A File.txt
09/17/2010 10:53 AM 15 Another File.txt
2 File(s) 24 bytes
Total Files Listed:
5 File(s) 678 bytes
5 Dir(s) 40,243,372,032 bytes free
Here is the build log:
Build started 9/17/2010 12:05:29 PM.
Project "C:\Builds\1\Scratch\Test Build\Sources\user\Test\Test.proj" on node 1 (default targets).
Build:
Output Dir: C:\Builds\1\Scratch\Test Build\Binaries\
dir /s > C:\Builds\1\Scratch\Test Build\Binaries\Dir2.txt
The system cannot find the path specified.
C:\Builds\1\Scratch\Test Build\Sources\user\Test\Test.proj(24,3): error MSB3073: The command "dir /s > C:\Builds\1\Scratch\Test Build\Binaries\Dir2.txt" exited with code 1.
Done Building Project "C:\Builds\1\Scratch\Test Build\Sources\user\Test\Test.proj" (default targets) -- FAILED.
Build FAILED.
"C:\Builds\1\Scratch\Test Build\Sources\user\Test\Test.proj" (default target) (1) ->
(Build target) ->
C:\Builds\1\Scratch\Test Build\Sources\user\Test\Test.proj(24,3): error MSB3073: The command "dir /s > C:\Builds\1\Scratch\Test Build\Binaries\Dir2.txt" exited with code 1.
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.14
Am I going about this completely wrong?
Your code works fine in my computer.
However : you should instantiate OutDir property either by passing it in Command-Line invokation :
c:\WINDOWS\Microsoft.NET\Framework\v4.0\MSBuild.exe test.proj /p:OutDir=MyNewDir
or with a PropertyGroup element :
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<OutDir>MyNewDir</OutDir>
</PropertyGroup>
<Target Name="Build">
<Message Text="Output Dir: $(OutDir)" />
<MakeDir Directories="$(OutDir)" />
<Exec Command='dir /s > \\ANetworkPath\dir.txt
dir /s > "$(OutDir)\Dir2.txt"'/>
</Target>
</Project>
Notice the \ added in the dir command.
EDIT : I get it : you have a space in your output path. The command dir /s > my path\Dir2.txt is not gonna work unless you encapsulate the path with quotes. Try the following commands in the dos shell :
mkdir C:\Builds\1\Scratch\Test Build\Binaries\
mkdir "C:\Builds\1\Scratch\Test Build\Binaries\"
You will notice the difference (the first line creates two directories one C:\Builds\1\Scratch\Test and one .\Build\Binaries). I edited my code above to add quotes.
This will also work.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<Exec Command='dir /s > Dir2.txt'/>
<Copy SourceFiles='Dir2.txt' DestinationFolder='$(OutDir)' />
</Target>
</Project>