Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Visual Studio 2017 "Stand-Alone Code Analysis Tool" missing Microsoft.Build, Version=14.0.0. #18140

Closed
aodendaal opened this issue Mar 24, 2017 · 4 comments
Assignees

Comments

@aodendaal
Copy link

Version Used:

Steps to Reproduce:

  1. Install Visual Studio Enterprise 2017 and include Visual Studio extension development workload with optional VC++ 2017 v141 toolset (x86,x64)
  2. Run VS and go to Tools -> Extensions and Updates
  3. Find .NET Compiler Platform SDK and click Download
  4. Restart VS
  5. Create a new Stand-Alone Code Analysis Tool project found under Templates -> Visual C# -> Extensibility (.NET Framework 4.6 or greater)
  6. In the Main function write
    var workspace = Microsoft.CodeAnalysis.MSBuild.MSBuildWorkspace.Create();
  7. Run Debug

Expected Behavior:
Code executes without exceptions

Actual Behavior:
System.Reflection.ReflectionTypeLoadException raised with multiple of the same LoaderExceptions:
Could not load file or assembly 'Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
Could not load file or assembly 'Microsoft.Build.Tasks.Core, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

I tried adding a reference to Microsoft.Build and Microsoft.Build.Tasks.Core but I only have versions 4.0.0.0 and 15.1.0.0

How do I get the correct references because either the template is using old references or I'm missing the older versions

@jmarolf
Copy link
Contributor

jmarolf commented Mar 24, 2017

@aodendaal a workaround here would be:

  1. Add an App.config file to your console project with the following contents
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build"
                          publicKeyToken="b03f5f7f11d50a3a"
                          culture="neutral" />
        <bindingRedirect oldVersion="14.0.0.0"
                         newVersion="15.1.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build.Framework"
                          publicKeyToken="b03f5f7f11d50a3a"
                          culture="neutral" />
        <bindingRedirect oldVersion="14.0.0.0"
                         newVersion="15.1.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Build.Tasks.Core"
                          publicKeyToken="b03f5f7f11d50a3a"
                          culture="neutral" />
        <bindingRedirect oldVersion="14.0.0.0"
                         newVersion="15.1.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>
  1. Add 15.1 references to Microsoft.Build, Microsoft.Build.Framework, and Microsoft.Build.Tasks.Core

@jmarolf jmarolf self-assigned this Mar 24, 2017
@aodendaal
Copy link
Author

Thanks! That works.

I also had to apply a bindingRedirect for System.Collections.Immutable

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

@jmarolf
Copy link
Contributor

jmarolf commented Mar 24, 2017

@asecchia I think the fix here is to have the templates add the redirects and msbuild references automatically for you. Thanks for reporting this bug.

@jmarolf
Copy link
Contributor

jmarolf commented Dec 15, 2017

Issue moved to dotnet/roslyn-sdk #69 via ZenHub

@jmarolf jmarolf closed this as completed Dec 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants