MSBuild cannot build my x86 program - msbuild

I have a program called A. It produces a file, A.exe. A.exe MUST run as a x86 program, and is thus build as one. A.exe refers to B.dll and C.dll.
B.dll and C.dll is set to build as x86 programs to make them available to A.exe
I am fairly new to this building with msbuild.exe so im still learning. I made a buildfile that uses the msbuild task to build my application (A)'s project (.csproj) file. I can easily build everything from within Visual Studio.
When i build from my msbuild (commandline) i get this error: "An attempt was made to load an assembly with an incorrect format B.exe.
<Target Name="Compile">
<Message Text="Compiling"/>
<ItemGroup>
<myproject Include="A.csproj"/>
</ItemGroup>
<MSBuild Projects="#(myproject)" Properties="Configuration=Release;Platform=x86"/>
</Target>

There is no need to build the dlls as x86. They should be build for any platform. When they are loaded by a .exe built for x86 the JIT compiler will compile them for the target chosen for the .exe (i.e. x86 if the .exe is built for x86).
Can't help you with msbuild though :-)

Related

How to use MsBuild.exe to build a fortran/c mixed project?

1. Background
I have a project which is managed by cmake, I then generate the solution files by Visual Studio 2019 geneartor. The folder strucutre looks like:
- main.sln
- fotran_proj.vfproj (output a static lib libfortran.lib)
- C_proj.vcxproj (dependent on libfortran.lib)
- ALL_BUILD.vcxproj
It contains both fortran and c projects, and c project is dependent on fortran project.
I want to build the whole solution from commandline by msbuild.exe.
2. Environment
I use VS2019 with Intel Fortran Compiler on win10.
3. Question
When I try to use msbuild.exe to build it:
MSBuild.exe /t:build ALL_BUILD
It simply build the vcxproj part and ignore the vfproj parts. Why? How can I achieve this?
To the best of my knowledge, you can't do this. Intel Fortran's build system isn't recognized by msbuild, though that integration might happen sometime in the future.
What you can do is use devenv from the command line to build your mixed-language solution. From an Intel Fortran command prompt window (or one where you have established the Intel environment), type devenv /? to see the usage and options. For example, I built a mixed-language solution as follows:
devenv C_calls_F.sln /build "Debug|Win32"

Is it possible to build cmake projects directly using MSBuildTools

Currently we are planning to use VS2017 with a cmake project. Inside Visual Studio this works quite like a charm.
Now want to run our builds as part of CI on a dedicated build master running MSBuildTools.
Is it possible to directly run the build using the msbuild command, without creating solution files with cmake? Optimally, I would even use the CMakeSettings.json used from VS2017.
Use the build-tool-mode of CMake for this. It uses the underlying default build tool which is MSBuild for Visual Studio Generators.
From the build directory call:
cmake --build . --target ALL_BUILD --config Release -- /nologo /verbosity:minimal /maxcpucount
and you get a fast, nearly quiet build. To install use INSTALL target, for running your tests if configured use RUN_TESTS target.
Is it possible to directly run the build using the msbuild command, without creating solution files with cmake?
Is it possible to directly run the build using the msbuild command, without creating solution files with cmake?
As far as I know, CMake produces Visual Studio Projects and Solutions seamlessly. So you can produce projects/solutions.
The only tricky part is to remember to make any changes in the cmake files, rather than from within Visual Studio.
In particular, each CMake project will create a Visual Studio solution (.sln file), while all of the CMake targets belonging to that CMake project will appear as Visual Studio projects within the corresponding solution.
CMake Visual Studio
project <-> Solution (.sln)
Target <-> Project (.vcxproj)
You can check cmake-and-visual-studio for more details.
Since MSbuild can build both solution files and project files, so you could also call msbuild INSTALL.vcxproj
Is it possible to even use the CMakeSettings.json used in VS2017?
The answer is yes, check the blog for details.
If your CMake project requires additional settings to configure the
CMake cache correctly, you can customize these settings by creating a
CMakeSettings.json file in the same folder with the root
CMakeLists.txt. In this file you can specify as many CMake
configurations as you need – you will be able to switch between them
at any time.
You can create the CMakeSettings.json file by selecting the Project >
Edit Settings > path-to-CMakeLists (configuration-name) menu entry.

MSBuild-Referenced DLLs not copying to output bin

I was a newbie, a little bit knowledge of visual studio, msbuild and scripting.
I was assigned to a task, to create an automation script for building project using MSbuild and the project has three different configuration and I need to build it sequentially because some projects depend on the output dlls of the other configuration, when building the first configuration it succeed but when I reach the second and third configuration it failed. Because reference DLLs were not copied on the ouput bin of selected configuration causing it to missing assembly reference on some projects. And, the thing is I can't edit the projects, it was only for me to view.
Any help on how could I successfully build it.
My script looks like this:
& $msbuild ($master_sln) /t:Clean /p:Configuration=FirstConfiguration /p:Platform="Any CPU"
& $msbuild ($master_sln) /t:Rebuild /p:Configuration=FirstConfiguration /p:Platform="Any CPU"
& $msbuild ($master_sln) /t:Build /p:Configuration="SecondConfiguration" /p:Platform="Any CPU" /p:BuildProjectReferences=false
& $msbuild ($master_sln) /t:Build /p:Configuration="ThirdConfiguration" /p:Platform="Any CPU" /p:BuildProjectReferences=false

What is the MSBuild equivalent to ant's -project-help?

I come from an ant background, and I'm starting to use msbuild. I want to create a .proj file with targets for clean, compile, deploy, etc. In ant, I would expect my user to run ant -project-help to get a list of the targets with their descriptions. There doesn't appear to be anything like this with msbuild, so I was thinking of setting DefaultTargets to "Help" and adding this target:
<Target Name="Help">
<Message Text="/t:Clean - Remove all bin folders and generated files"/>
<Message Text="/t:Compile - Generate assembly"/>
<Message Text="/t:Deploy - Install the assembly"/>
</Target>
When I run msbuild, I see this:
Microsoft (R) Build Engine Version 3.5.30729.1
[Microsoft .NET Framework, Version 2.0.50727.3053]
Copyright (C) Microsoft Corporation 2007. All rights reserved.
Build started 5/13/2010 9:00:00 AM.
Project "C:\MyProject\MyProject.proj" on node 0 (default targets).
/t:Clean - Remove all bin folders and generated files
/t:Compile - Generate assembly
/t:Deploy - Install the assembly
Done Building Project "C:\MyProject\MyProject.proj" (default targets).
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:00.05
My target description are hidden among all the other output.
It feels like I have a paradigm-mismatch here. What's the best way to provide the build functionality I want so that users know where to find each target?
I'm afraid there is no clean way to do what you want. Creating a default help target is a good idea.
To have a cleaner output, you could set the Importance attribute of Message task to high to have your messages standing out more.
<Target Name="Message">
<Message Text="/t:Clean - Remove all bin folders and generated files" Importance="high"/>
<Message Text="/t:Compile - Generate assembly" Importance="high"/>
<Message Text="/t:Deploy - Install the assembly" Importance="high"/>
</Target>
You could also run MSBuild with the following argument to clean your output :
msbuild [ProjectFile.proj] /v:m /nologo
You'll have this output :
/t:Clean - Remove all bin folders and generated files
/t:Compile - Generate assembly
/t:Deploy - Install the assembly

How do I set the Output directory for a C++ project built by msbuild?

I have a MSBuild .proj file that is compiling a mixture of C# and C++ projects.
The C# projects compile output (.exe/.dlls) to the OutputPath I specify, but when I specify OutputPath for the C++ projects (which calls vcbuild.exe), the OutputPath is ignored and instead goes into the directory specified in the Property Pages for the .vcproj.
Here's my MSBuild task:
<MSBuild Projects="$(SourceFolder)\$(NativeSolutionName)"
Targets="$(BuildTargets)"
Properties="Configuration=$(Configuration);PlatformName=Win32;OutputPath=$(ToolsOutputDir)">
</MSBuild>
How can I specify that the C++ output files should go to the same directory as the C# output files $(ToolsOutputDir)?
I was able to make this work by doing the following:
1) Installing the Microsoft SDC MSBuild Tasks Library
2) In the property pages for the C++ projects, setting the output directory to $(OutputPath).
3) Adding a SDC task to set the environment variable OutputPath before building the C++ projects via VCBuild:
<Microsoft.Sdc.Tasks.SetEnvironmentVariable Variable="OutputPath" Value="$(ToolsOutputDir)" Target="Process"/>
<!-- Build any CPP code x86 -->
<MSBuild Projects="$(SourceFolder)\$(NativeSolutionName)"
Targets="$(BuildTargets)"
Properties="Configuration=$(Configuration);PlatformName=Win32;OutputPath=$(ToolsOutputDir)">
</MSBuild>