publish core build environment control - msbuild

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' " />

Related

How to skip some targets using commnd line (CMake)

I'm have dependency on Xerces-c++ and for instal target it always builds example executables and documentation. That consumes ~50% of build time (6 mins on my build VM).
My current build command is cmake --build ${proj}\build_${platform} --config RelWithDebInfo --target install --parallel.
How can I skip non essential targets?
It's third party dependency, so I don't want to modify CMakeLists.txt.
According to the source there is no option to control the build of samples
add_subdirectory(samples)
ref: https://github.com/apache/xerces-c/blob/master/CMakeLists.txt#L172
But you can patch it !
option(BUILD_SAMPLES "Build samples" ON)
message(STATUS "Build samples: ${BUILD_SAMPLES}")
...
if(BUILD_SAMPLES)
add_subdirectory(samples)
endif()
note: you can also enable CMP0077 if you have a super build...

travis build fails running msbuild due to MSB4019

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.

msbuild Dotfuscator exec task giving error MSB3073 exited with code 1

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.

Restart Apache using Ant script for both unix and windows Systems?

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.

Generating output content with MSBuild and no VS projects

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>