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>
Related
I am trying to build automatically a golang project in a windows environment with travis and to package the .exe making use of msbuild and wix.
The very same configuration works with Github actions and therefore I believe that both the .wixproj and the wxs are correct and there is some issue with the configuration of msbuild in the travis installation, but I have no more clues.
Possibly the msbuild installed by travis does not include the required wix toolset, I tried to install them, however while creating the package the error persist
The error
C:\Users\travis\gopath\src\github.com\gallo-cedrone\nri-elasticsearch\pkg\windows\nri-amd64-installer\nri-installer.wixproj" (default target) (1) ->
C:\Users\travis\gopath\src\github.com\gallo-cedrone\nri-elasticsearch\pkg\windows\nri-amd64-installer\nri-installer.wixproj(34,5):
error MSB4019: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\WiX\v3.x\Wix.targets" was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
.travis
...
- os: windows
env:
- MSBUILD_PATH="c:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin"
before_script:
- powershell Install-WindowsFeature Net-Framework-Core
- cinst -y wixtoolset
script:
- export PATH=$MSBUILD_PATH:$PATH
- go test ./src/
- go build -v -o ./target/bin/windows_amd64/nri-elasticsearch.exe ./src/
- msbuild.exe -version
- cd ./pkg/windows/nri-amd64-installer/ ; pwd ; env ; msbuild.exe ./nri-installer.wixproj
...
travis job logs
I found a solution thanks to enter link description here
Basically I was installing the wixtools, however the installation folder was not the expected one by vs2017.
It can be fixed simply by changing:
<Import Project="$(WixTargetsPath)" />
with:
<Import Project="$(WixTargetsPath)" Condition=" '$(WixTargetsPath)' != '' " />
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets" Condition=" '$(WixTargetsPath)' == '' AND Exists('$(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets') " />
and removing the WixTargetsPath clouses contitions.
What controls the environment passed to webpack when invoking Publish triggers a build? Look at this:
1>------ Build started: Project: MeshCut, Configuration: Debug Any CPU ------
1>MeshCut -> D:\MeshCut\bin\Debug\netcoreapp2.1\MeshCut.dll
2>------ Publish started: Project: MeshCut, Configuration: Debug Any CPU ------
MeshCut -> D:\MeshCut\bin\Debug\netcoreapp2.1\MeshCut.dll
npm install
audited 11025 packages in 7.787s
found 0 vulnerabilities
node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod
Hash: dadea967a4be0fa40482
Version: webpack 4.22.0
. . .
Publish Succeeded.
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========
In the first line it is obviously a debug build but this line
node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod
is clearly passed env.prod which is making it impossible to find out why there is an error in production that doesn't occur when the server is run from the IDE.
I tried setting an environmnent variable ASPNETCORE_ENVIRONMENT to "Development" but this was not helpful, probably because this is a run-time thing.
Ultimately this is an msbuild thing. The combination of a pubxml file and the csproj file are the inputs to msbuild.
Within the csproj file env.prod is a literal. IF there were some way to make the this value depend on the build type (release/debug) the problem could be resolved.
There is another question inspired by fundamentally the same problem, but the asker is satisfied with discovering that he can control it by editing the csproj. This is not helpful for respecting release/debug.
It's an MSBUILD thing. That means look in the csproj file and sure enough we find this
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" />
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
<Exec Command="node node_modules/webpack/bin/webpack.js --env.prod" />
and it is easy to find the culprits in the second and third Exec statements.
The question remaining is how to either conditionally specify a parameter value, or how to conditionally specify a completely different command-line.
This Microsoft documentation appears to describe how to do the second option, but msbuild didn't like my attempt to wrap the exec elements with choose and when elements and I could still use some help.
It's an MSBUILD thing. That means look in the csproj file and sure enough we find this
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" />
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod" />
<Exec Command="node node_modules/webpack/bin/webpack.js --env.prod" />
and it is easy to find the culprit in the second of the Exec statements.
Exec supports a Condition attribute. Fortunately elsewhere in the CSPROJ file one of the targets is already conditional on the exact condition we require. With a little copy/paste and tweaking, the code becomes...
<Target Name="PublishRunWebpack" AfterTargets="ComputeFilesToPublish">
<!-- As part of publishing, ensure the JS resources are freshly built in production mode -->
<Exec Command="npm install" />
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.dev"
Condition=" '$(Configuration)' == 'Debug' " />
<Exec Command="node node_modules/webpack/bin/webpack.js --env.dev"
Condition=" '$(Configuration)' == 'Debug' " />
<Exec Command="node node_modules/webpack/bin/webpack.js --config webpack.config.vendor.js --env.prod"
Condition=" '$(Configuration)' == 'Release' " />
<Exec Command="node node_modules/webpack/bin/webpack.js --env.prod"
Condition=" '$(Configuration)' == 'Release' " />
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.
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.
I searched and found some ques as ** how to restart apache using nant script ** and tried similar code but got some message..i tried this code
<exec executable="${APACHE_HOME}/bin/httpd.exe">
<arg value="-k"/>
<arg value="restart"/>
</exec>
OUTPUT:
apache-restart:
[exec] [Tue Nov 15 19:58:18 2011] [error] (OS 2)The system cannot find the file specified. : No installed ser
vice named "Apache2.2".
[exec] Result: 2
And the reason for this is i guess Apache is not installed as a windows service.
I tried both but both have problems:
1) my cursor kept blinking and next statement echo was not reached.
<target name="test" depends="init">
<exec executable="${APACHE_HOME}/bin/httpd.exe">
</exec>
<echo message="hello "/>
</target>
OUTPUT:
test:
2)where is this taskkill file present ??
<target name="test" depends="init">
<exec executable="taskkill /im httpd.exe">
</exec>
<echo message="hello "/>
</target>
OUTPUT:
Execute failed: java.io.IOException: Cannot run progra
"taskkill \im httpd.exe": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:460)
Well, install the service first with httpd.exe -k install
Or you can execute taskkill /im httpd.exe to kill apache and httpd.exe to start it again. You may want to add /f switch to taskkill also.