1

I have a c# project and in the solution, the platform target is AnyCPU. While I have a build program that will daily build this solution and it uses msbuild.exe. The command likes:

MSBuild D:\my.sln /p:Configuration=Release /p:Platform=x86 /t:rebuild ....

Here I specify the compiled platform should be x86.

I my opinion, the msbuild.exe should overwrite solution configure and the output should be x86 exe instead of anyCPU type.

I try these codes into this project:

        PortableExecutableKinds peKind;
        ImageFileMachine machine;

        Assembly.GetExecutingAssembly().ManifestModule.GetPEKind(out peKind, out machine);

The test result suggest, the exe is AnyCPU mode (ILOnly), not what expected. In such condition, how can i know my program it compiler by x86 or x64, by code?

Thanks. Li

1 Answer 1

1

I prefer not to build the .sln file but use use a little build script with msbuild.exe

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Deploy" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">


<Target Name="BuildProjects" >

    <ItemGroup>      
        <BuildProjectsInputFiles Include="**\MainProject\*.??proj" />
        <BuildProjectsInputFiles Include="**\AnotherProject\*.??proj" />
    </ItemGroup>

    <MSBuild Projects="@(BuildProjectsInputFiles)" Properties="Configuration=$(Configuration);OutputPath=$(MSBuildProjectDirectory)\Deploy\bin\%(BuildProjectsInputFiles.FileName)">
        <Output TaskParameter="TargetOutputs"
                ItemName="BuildProjectsOutputFiles" />
    </MSBuild>

</Target>

</Project>

Now I use msbuild with this call

msbuild.exe build.xml /p:OutputPath=bin\Debug;Configuration=Release;Platform=x86 /target:BuildProjects

And that works

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks SchlaWiener. I just update my post. I can't modified the build scripts because that out of my territory. So my question shrinks to how can i get x86/x64 info by code? After testing, if i compiler with /p:Platform=x86 or /p:Platform=x64, the dll actually is different (I try to dynamically load x86 .net dll inside x64 compiled program, an error happen) regardless both peKind = ILOnly.
Check IntPtr.Size which should be different for x86/x64 processes.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.