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



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

MSBuild D:\my.sln/p:配置=发布/p:平台=x86/t:重建。。。。

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

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

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

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

测试结果表明,exe是AnyCPU模式(ILOnly),而不是预期的。在这种情况下,我怎么能知道我的程序是x86或x64编译的,通过代码?

谢谢。李

我不喜欢构建.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)Deploybin%(BuildProjectsInputFiles.FileName)">
<Output TaskParameter="TargetOutputs"
ItemName="BuildProjectsOutputFiles" />
</MSBuild>
</Target>
</Project>

现在我使用msbuild调用

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

这对有效

相关内容

最新更新