首页 > 解决方案 > MsBuild.exe 与 Visual Studio 2017 不同的输出

问题描述

我在使用 Visual Studio 2017 构建项目时遇到问题,一切正常,但在尝试使用 msbuild.exe 构建项目时,输出不同且无法正常工作。

msbuild 已执行

msbuild.exe "myproj.csproj" /p:Configuration=Release;Platform="Any CPU";OutputPath="c:\pub\myproj"

Visual Studio 构建设置: 在 Visual Studio 2017 中构建设置 我做错了什么,我怎样才能让 msbuild 产生与 Visual Studio 构建相同的输出?

尝试执行使用 msbuild 生成的代码时出现的错误

Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Reflection.ReflectionTypeLoadException
   at System.Reflection.RuntimeModule.GetTypes(System.Reflection.RuntimeModule)
   at System.Reflection.RuntimeModule.GetTypes()
   at System.Reflection.Assembly.GetTypes()
   at MyProj.V2.Infrastructure.Bootstrappring.BootstrapperBase+<>c__DisplayClass14_0.<RegisterInfrastructureComponents>b__0(AutoMapper.IMapperConfigurationExpression)
   at AutoMapper.MapperConfiguration.Build(System.Action`1<AutoMapper.IMapperConfigurationExpression>)
   at AutoMapper.Mapper.Initialize(System.Action`1<AutoMapper.IMapperConfigurationExpression>)
...

它可能表示使用 msbuild 构建时缺少某些程序集或引用已损坏。我检查了代码中引用的所有 .dll 都在两种情况下的输出中。

标签: msbuildvisual-studio-2017

解决方案


也许您可以尝试: 1.使用来自以下位置的 msbuild.exe:

C:\Program Files (x86)\Microsoft Visual Studio\2017\VSversion\MSBuild\15.0\Bin

2.去掉“Any CPU”中的空格,应该是Platform="AnyCPU"而不是“Any CPU”

3.取消勾选优化代码,看看是否有区别


推荐阅读