简体   繁体   English

使用msbuild.exe生成C#项目不会覆盖项目目标平台配置吗?

[英]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. 我有一个ac#项目,在解决方案中,平台目标是AnyCPU。 While I have a build program that will daily build this solution and it uses msbuild.exe. 虽然我有一个生成程序,它将每天生成此解决方案,并且它使用msbuild.exe。 The command likes: 该命令喜欢:

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

Here I specify the compiled platform should be x86. 在这里,我指定编译平台应为x86。

I my opinion, the msbuild.exe should overwrite solution configure and the output should be x86 exe instead of anyCPU type. 我认为,msbuild.exe应该覆盖解决方案配置,并且输出应该是x86 exe而不是anyCPU类型。

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. 测试结果表明,exe是AnyCPU模式(ILOnly),而不是预期的。 In such condition, how can i know my program it compiler by x86 or x64, by code? 在这种情况下,我如何通过代码知道我的程序是x86还是x64编译器?

Thanks. 谢谢。 Li

I prefer not to build the .sln file but use use a little build script with msbuild.exe 我更喜欢不构建.sln文件,而是使用带有一点构建脚本的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

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

And that works 那行得通

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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