Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Visual studio 2015 MSBuild 14生成的可执行文件需要比引用文件更早的依赖项_Visual Studio 2015_Roslyn_Msbuild 14.0 - Fatal编程技术网

Visual studio 2015 MSBuild 14生成的可执行文件需要比引用文件更早的依赖项

Visual studio 2015 MSBuild 14生成的可执行文件需要比引用文件更早的依赖项,visual-studio-2015,roslyn,msbuild-14.0,Visual Studio 2015,Roslyn,Msbuild 14.0,我有一个VS 2015 C#解决方案,带有一个主可执行文件和一些库项目。这是一个代码分析器工具,它还使用Roslyn和MSBuild,因此主程序集需要Microsoft.CodeAnalysis和Microsoft.Build from NuGet。我最近的任务是将以前的包从1.x更新到2.x。它不是很流畅,但我成功了,它现在需要Microsoft.CodeAnalysis 2.8.2和Microsoft.Build 15.7.179。直接从VisualStudio构建时,一切都按预期工作 但是

我有一个VS 2015 C#解决方案,带有一个主可执行文件和一些库项目。这是一个代码分析器工具,它还使用Roslyn和MSBuild,因此主程序集需要Microsoft.CodeAnalysis和Microsoft.Build from NuGet。我最近的任务是将以前的包从1.x更新到2.x。它不是很流畅,但我成功了,它现在需要
Microsoft.CodeAnalysis 2.8.2
Microsoft.Build 15.7.179
。直接从VisualStudio构建时,一切都按预期工作

但是,当我从命令行使用MSBuild 14构建相同的解决方案(从而生成相同的csproj文件)时,生成的可执行文件不同,并且在运行时尝试创建MSBuild工作区时,以下堆栈崩溃:

Nem kezelt kivétel: System.Reflection.ReflectionTypeLoadException: Egy vagy több kért típus nem tölthető be. További tájékoztatást a LoaderExceptions tulajdonság lekérésével kaphat.
   a következő helyen: System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   a következő helyen: System.Reflection.RuntimeAssembly.get_DefinedTypes()
   a következő helyen: System.Composition.Hosting.ContainerConfiguration.<>c.<WithAssemblies>b__16_0(Assembly a)
   a következő helyen: System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
   a következő helyen: System.Composition.TypedParts.TypedPartExportDescriptorProvider..ctor(IEnumerable`1 types, AttributedModelProvider attributeContext)
   a következő helyen: System.Composition.Hosting.ContainerConfiguration.CreateContainer()
   a következő helyen: Microsoft.CodeAnalysis.Host.Mef.MefHostServices.Create(IEnumerable`1 assemblies)
   a következő helyen: Microsoft.CodeAnalysis.Host.Mef.DesktopMefHostServices.get_DefaultServices()
   a következő helyen: Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create(IDictionary`2 properties)
   a következő helyen: Columbus.CSAN.RoslynParser.AbstractOpen..ctor(String path, String configuration, String platform)
   a következő helyen: Columbus.CSAN.RoslynParser.FileOpen..ctor(String path, String config, String platform)
   a következő helyen: Columbus.CSAN.RoslynParser.AbstractOpen.CreateInstance(String path, String configuration, String platform)
   a következő helyen: Columbus.CSAN.MainProgram.Main(String[] args)
当然,它找不到System.Collections.Immutable的1.2.0.0,因为我们需要packages.config中的1.3.1(这会引起更多的混淆,是程序集版本1.2.1.0),通过以下链:

Microsoft.CodeAnalysis 2.8.2
Microsoft.CodeAnalysis.CSharp.Workspaces 2.8.2
Microsoft.CodeAnalysis.CSharp 2.8.2
Microsoft.CodeAnalysis.Common 2.8.2
System.Collections.Immutable 1.3.1
该命令如下所示:
msbuild All.sln/t:Build/p:Configuration=Debug/p:Platform=x64/verbosity:diagnostic

在问题项目引用下的MSBuild输出中:

System.Collections.Immutable, Version=1.2.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL
    HintPath = ..\..\packages\System.Collections.Immutable.1.3.1\lib\portable-net45+win8+wp8+wpa81\System.Collections.Immutable.dll
    Private = True
我真的不明白为什么它在运行时需要一个旧版本的库,因为
1.2.0.0
即使在详细的构建日志中也不会出现,只有包
1.3.1
中的
1.2.1.0


澄清一下:我正在用VS2015/MSBuild14构建我自己的项目,因为它仅是C#6.0,但希望它能够分析C#7.0,这就是为什么我要求将Roslyn 2和MSBuild15作为一个包。

该项目引用的某些程序集引用的是1.2.0.0。您可以使用或只是添加一个
EnableLog
,将
DWORD
1
添加到
HKEY\U LOCAL\U MACHINE\Software\Microsoft\Fusion
注册表项中

但要解决此问题,您需要在配置文件中添加:

<runtime>  
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v1.0.3705">  
        <assemblyIdentity name="System.Collections.Immutable"  
                          publicKeyToken="b03f5f7f11d50a3a"  
                          culture="neutral" />  
            <bindingRedirect oldVersion="0.0.0.0-1.2.1.0"  
                             newVersion="1.2.1.0"/>
        </dependentAssembly>
    </assemblyBinding>  
</runtime>

我接受了你的答案,因为问题就要解决了。NuGet确实使用所需的重定向创建了app.config,但我们的构建系统没有将生成的x.exe.config复制到包中。这就是为什么它在VS中工作,而不是在MSBuild中工作。
<runtime>  
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1" appliesTo="v1.0.3705">  
        <assemblyIdentity name="System.Collections.Immutable"  
                          publicKeyToken="b03f5f7f11d50a3a"  
                          culture="neutral" />  
            <bindingRedirect oldVersion="0.0.0.0-1.2.1.0"  
                             newVersion="1.2.1.0"/>
        </dependentAssembly>
    </assemblyBinding>  
</runtime>