【问题标题】:Build C# project with msbuild.exe doesn't overwrite project target platform configuration?使用 msbuild.exe 构建 C# 项目不会覆盖项目目标平台配置?
【发布时间】:2012-11-04 23:20:48
【问题描述】:

我有一个 c# 项目,在解决方案中,平台目标是 AnyCPU。虽然我有一个构建程序,它将每天构建这个解决方案并且它使用 msbuild.exe。命令喜欢:

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

这里我指定编译的平台应该是x86。

我认为,msbuild.exe 应该覆盖解决方案配置,并且输出应该是 x86 exe 而不是任何CPU 类型。

我在这个项目中尝试了这些代码:

        PortableExecutableKinds peKind;
        ImageFileMachine machine;

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

测试结果提示,exe是AnyCPU模式(ILOnly),不是预期的。 在这种情况下,我怎么知道我的程序是用 x86 还是 x64 编译的?

谢谢。 李

【问题讨论】:

    标签: c# msbuild x86 64-bit platform


    【解决方案1】:

    我不喜欢构建 .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>
    

    现在我在这个调用中使用 msbuild

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

    这行得通

    【讨论】:

    • 谢谢施拉维纳。我只是更新我的帖子。我无法修改构建脚本,因为那超出了我的领域。所以我的问题缩小到如何通过代码获取 x86/x64 信息?经过测试,如果我用 /p:Platform=x86 或 /p:Platform=x64 编译,dll 实际上是不同的(我尝试在 x64 编译的程序中动态加载 x86 .net dll,发生错误)不管 peKind = ILOnly .
    • 检查 IntPtr.Size 对于 x86/x64 进程应该是不同的。
    猜你喜欢
    • 2011-07-23
    • 1970-01-01
    • 2011-02-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    相关资源
    最近更新 更多