简体   繁体   中英

Build C# project with msbuild.exe doesn't overwrite project target platform configuration?

I have ac# 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM