MSBuild Custom Activities in VS 2012 - c#

I need to rebuild a set of custom TFS build activities, and am getting the following error. I'm under the impression from googling around that this results from MS pulling the Microsoft.Build.Engine package out of the 4.0 Framework and including it with the VS tooling.
The primary reference "Microsoft.TeamFoundation.Build.Workflow, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" could not be resolved because it has an indirect dependency on the .NET Framework assembly "Microsoft.Build.Engine, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which has a higher version "12.0.0.0" than the version "4.0.0.0" in the current target framework.
Any ideas what I can do about this? I am targeting the 4.5 framework, have VS 2012 and 2013 installed, though using 2012 to build this package.

Check the reference to Microsoft.Build.Engine or the reference path. The MsBuild binary and its dependencies has moved from the c:\windows\Microsoft.NET folder to: C:\Program Files (x86)\MSBuild\12.0\Bin

I had a similar problem, and, in general, Lee Higgitt's answer is correct. The reason is that Microsoft.TeamFoundation.Build.Workflow v.12 has a dependency on Microsoft.Build.dll v.12, which I've learned somehow requires that the build be done using Microsoft.Build.Tasks.v12.0.dll. If the MSBuild property VisualStudioVersion is set to 12.0 (e.g. when the sln is a VS 2013 sln), then Microsoft.Build.Tasks.v12.0.dll is used. In contrast, if VisualStudioVersion is set to 11.0 (e.g. when it's a VS 2012 sln), then
Microsoft.Build.Tasks.v4.0.dll is used. The v4 Tasks dll produces the error; the v12 Tasks dll doesn't. In general, then, upgrading the sln to VS 2013 will fix it.
However, if one is using a TFS build server, it's a different story. Even if VisualStudioVersion is 12.0, since C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe is used to do the build and only the v4 Tasks dll is present in that directory, the build is forced to use the v4 Tasks dll, causing the error to be produced.
You might think that forcing the build to use the x86 version of MSBuild would do the job, but, C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe still only contains the v4 Tasks dll!
From my command line testing, when the build is done with C:\Program Files (x86)\MSBuild\12.0\Bin\MSBuild.exe, the v12 Tasks dll is present in that dir and is used, so the build works!
Also, I've oversimplified the problem above. I tried copying the v12 Tasks dll and Microsoft.Build.Utilities.v12.0.dll into
C:\Windows\Microsoft.NET\Framework\v4.0.30319, but that didn't allow the instance of msbuild in that directory to build my sln successfully.
In short, I think this must be a Microsoft bug. I'll create a ticket with them and update this thread as I learn anything.
Update:
Here's the issue on Microsoft Connect.
Update 2:
As one can see from the the issue on Microsoft Connect, for the TF Build case, if one uses the template that comes with TFS 2013, this issue is not repro'ed (though I haven't had a chance to confirm this myself yet). So, to fix this issue...
If it's happening locally, upgrade the solution to VS 2013.
If it's on a TFS build server, make sure the logic of the latest template from Microsoft is being used.

I've been having the same issue in Visual Studio 2012.
I've re-created my solution in VS2013 and all of the issues go away! Not really a solution but if you've got access to 2013 then I recommend you try it.

Related

System.Runtime.Extensions Injection Errors in Visual Studio 2015

I'm running into an error which seems to be a combination of three factors, and I'm trying to find out if this is a known issue, and if there is a fix or work-around for it.
Factor 1: We are using Visual Studio 2015, update 3.
Factor 2: We are using .net 4.6.2. This version of .net is not included in VS2015, so it was added via the Developer Pack link, located here: https://www.microsoft.com/net/download/windows
Factor 3: We are using Microsoft.Extensions.Dependency Injection. Version 1.0.0, but the issue is reproducible in every version except 2.0.0, which does not appear to be compatible with .net 4.6.2
In order to most easily reproduce this, I am able to create a new solution in Visual Studio 2015, with a new empty web application project, targeting 4.6.2. I open the Nuget package manager, find Microsoft.Extensions.DependencyInjection, and include version 1.0.0 in my project. Build the project, and get this error:
Error CS1703 Multiple assemblies with equivalent identity have been imported: 'c:\Projects\DITest\packages\System.Runtime.Extensions.4.1.0\lib\net462\System.Runtime.Extensions.dll' and 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.6.2\Facades\System.Runtime.Extensions.dll'. Remove one of the duplicate references.
Does anyone have any idea why this might be happening? If I build targeting 4.6.1 it works fine, but we have other dependencies which necessitate 4.6.2. I do not currently have access to Visual Studio 2017, but if it turns out that necessary to make this code run properly, I can pursue it.
Every avenue I've explored regarding this has ended up in a dead-end.

Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependenc

An update occurred last night and now I find myself unable to do a ctrl + '.' for code suggestions in VS 2015. An error message comes up saying the following:
Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
I can still build and develop but this will be really annoying without this feature. I admit it, I am getting soft!
Anyone have a suggestion for fixing this bug?
As pointed out by #CaptainAmerica the solution is to update the CodeDom assembly from NuGet. One should point out how to do this in Visual Studio.
I found the solution here:
https://www.nuget.org/packages/Microsoft.CodeDom.Providers.DotNetCompilerPlatform/
Basically, in the Visual Studio menu select:
Tools-> Nuget Package Manager -> Package Manager Console
In the console that appears at the bottom of Visual Studio run this command:
Install-Package Microsoft.CodeDom.Providers.DotNetCompilerPlatform
If any of the options doesn't work, here is the detailed guide to handle this scenario....
First of all version is important. Notice the version mentioned in the error...
Could not load file or assembly 'Microsoft.CodeAnalysis, version= 1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
If you see above error it means that it's not able to find version 1.3.1. Now please create new VS project. No preferences, it can be just simple console application. Now once project template is ready, go to Package Manager and run following command with your specified version...
Install-Package Microsoft.CodeAnalysis -Version 1.3.1
This will install all packages. Let it complete. Once it's done. We don't need this newly created project at all. You can delete it completely. Seriously! you can delete it. We did this because we wanted that package installed at global nuget level. When you install something, nuget stores it at global level of your machine as well. Path will be something like this...
C:\Users\<<Your Windows User>>\.nuget\packages
You can know your path by following...
%USERPROFILE%\.nuget\packages
Now you will see your required Microsoft.CodeAnalysis.dll there in following folder...
C:\Users\<<Your Windows User>>\.nuget\packages\Microsoft.CodeAnalysis.Common\1.3.1\lib\net45
Please note that above path contains version number (1.3.1). If your version is different, look into that version folder.
Now that you have dll with you, all that you need to do is add that dll to GAC. For that you will need GacUtil.exe
This file get installed along with Visual Studio already. You can search "GacUtil" in C drive. For me it's there on below path...
C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools
Now run command prompt as Administrator and navigate current directory to your path containing GacUtil. The run below command to install that dll in GAC.
gacutil
-i C:\Users\<<You Windows User>>\.nuget\packages\Microsoft.CodeAnalysis.Common\1.3.1\lib\net45\Mi
crosoft.CodeAnalysis.dll
Basically providing path to dll we installed globally. It will show message on successful installation.
That's all! Now start your Visual Studio again and you will get this issue fixed.
I had the same problem with Visual Studio 2015 Update 2, to solve the problem globally for all solutions, update to Visual Studio 2015 Update 3. Here is a link: Download from here
I found this page and at the bottom of the page under "Compatibility with ASP.NET" it says that ASP.NET uses the nuget package Microsoft.CodeDom.Providers.DotNetCompilerPlatform to update the Microsoft.CodeAnalysis assemblies. So I updated the DotNetCompilerPlatform package from 1.0.0 to 1.0.3 and it works again! Yeah, life is good again!
To solve this problem for all solutions, I needed to install the assembly Microsoft.CodeAnalysis.dll directly to the GAC – Global Assemblies Cache.
I got the file Microsoft.CodeAnalysis.dll from C:/Users/[user]/.nuget/packages/Microsoft.CodeAnalysis.Common/1.3.2/lib/portable-net45+win8/Microsoft.CodeAnalysis.dll.
To install the assembly to the GAC, I used a PowerShell script from https://github.com/LTruijens/powershell-gac.
Finally, I managed to install the assembly to the GAC with the following command from PowerShell:
Add-GacAssembly [myPath]\Microsoft.CodeAnalysis.dll
I was also facing same issue. My visual studio 2015 version was 2.0. I upgraded it to version 3.
Issue got solved !!!
I was also facing same issue, Try installing Microsoft.CodeAnalysis.CSharp nuget package. And if its not resolved, check version of Microsoft.Net.Compilers in your project, I was having version as 1.0.0 which was causing issue so updated Microsoft.Net.Compilers nuget to v1.3.2.
Found solution here : Github discussion
I have solved the problem this way:
Update Visual studio 2015 to Update 3
from the menu chose View => Notifications => Visual Studio Update 3 and clicked the update button.
Today ! i got the same problem and i resolve it by restarting visual studio 2015 :)
I encountered this issue when trying to build someone's code from github.
I was opening it in VS 2019 but I also have VS 2022. Opening and building in VS 2022 just worked.
I fixed this issue by updating all Nuget Microsoft dependencies to v2.0.0. This was using VS 2017. I was using a preview version.
In my case, the error occurred after turning off Live Unit Testing and running tests manually.Some tests would fail with the above error message.
Going into Test --> Live Unit Testing --> Options and issuing "Delete Persisted Data" resolved the problem.
I fixed similar issue by deleting the .vs folder located inside the solution.
I found the missing assemblies in the NuGet package (After the first one was resolved there were mulitple otheres): https://www.nuget.org/packages/Microsoft.Net.Compilers/1.3.1-rc
Installed them using GacUtil from the Dev console.
Unfortunately the extensive solution with "nuget install/gacutil" here above couldn't work as the exact version of the dependency dll was not available.
The following solved my issue in our complex webform application was to perform within the solution in Visual Studio -> Tools -> Nuget -> console package manager
Update-Package -reinstall
In my case, I was getting this error because my Visual Studio Solution was trying to use TextTransform.exe during a pre-build step in one of the projects, but my local machine didn't have the TextTransform.exe at the path specified by my pre-build step and my first attempt at fixing that was to just copy TextTransform.exe from some other location to where Visual Studio expected it to be. That appears to have caused this problem, because TextTransform.exe has other silent dependencies.
My fix was to change the pre-build steps so instead of looking for the file at
C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating\14.0\TextTransform.exe
it would instead look in the Visual Studio install folder which had a bunch of other files, presumably one of which was a peer dependency of TextTransform.exe
C:\Program Files\Visual Studio\Common7\IDE\TextTransform.exe
That seemed to fix things for me.
I got the same problem, I am using VS2017 and installed Microsoft.EntityFrameworkCore.SqlServer 3.1.8, while in my VS2017 .Net core version is 2.1
So I downgraded my Microsoft.EntityFrameworkCore.SqlServer to 2.1.1 and restarted the solution.
The warning was gone !!
I had similar errors in VS2019 after upgrading project to .Net 5 according to https://learn.microsoft.com/en-us/aspnet/core/migration/31-to-50?view=aspnetcore-5.0&tabs=visual-studio.
error CS0006: Metadata file
'C:\Users\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll'
could not be found.
'C:\Users\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll' could not be founderror CS0006: Metadata file
The fix was to close and reopen VS 2019
Try adding Nuget Package Microsoft.VisualStudio.Web.CodeGeneration.Design to your project
This question is many years old and the answers are all fairly old as well. I only recently ran into a similar-enough issue that I feel sharing my experience here (although potentially not complete) is relevant.
D:\Code\C#\sdkrazortest>dotnet --version
6.0.401
D:\Code\C#\sdkrazortest>dotnet new webapp -o webapp1
The template "ASP.NET Core Web App" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/6.0-third-party-notices for details.
Processing post-creation actions...
Running 'dotnet restore' on D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj...
Determining projects to restore...
Restored D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj (in 102 ms).
Restore succeeded.
D:\Code\C#\sdkrazortest>cd webapp1
D:\Code\C#\sdkrazortest\webapp1>dotnet build
MSBuild version 17.3.1+2badb37d1 for .NET
Determining projects to restore...
All projects are up-to-date for restore.
REWRITECSS : error : [D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj]
An assembly specified in the application dependencies manifest (rzc.deps.json) was not found:
package: 'Microsoft.CodeAnalysis.Common', version: '4.3.0-3.22415.1'
path: 'lib/netcoreapp3.1/Microsoft.CodeAnalysis.dll'
Build FAILED.
REWRITECSS : error : [D:\Code\C#\sdkrazortest\webapp1\webapp1.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:10.32
I originally tried loading packages like the top comments here had suggested and realized this issue started happening shortly after install .net core 6. After seeing some SO comments on dotnet-aspnet-codegenerator being version-specific I tried to create my netcore3.1 app using an older version of the dotnet cli via global.json:
D:\Code\C#\sdkrazortest>type global.json
{
"sdk": {
"version": "3.1.403"
}
}
D:\Code\C#\sdkrazortest>dotnet new webapp -o webapp2
Getting ready...
The template "ASP.NET Core Web App" was created successfully.
This template contains technologies from parties other than Microsoft, see https://aka.ms/aspnetcore/3.1-third-party-notices for details.
Processing post-creation actions...
Running 'dotnet restore' on webapp2\webapp2.csproj...
Determining projects to restore...
Restored D:\Code\C#\sdkrazortest\webapp2\webapp2.csproj (in 187 ms).
Restore succeeded.
D:\Code\C#\sdkrazortest>cd webapp2
D:\Code\C#\sdkrazortest\webapp2>dotnet build
Microsoft (R) Build Engine version 16.7.0+7fb82e5b2 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.
Determining projects to restore...
All projects are up-to-date for restore.
webapp2 -> D:\Code\C#\sdkrazortest\webapp2\bin\Debug\netcoreapp3.1\webapp2.dll
webapp2 -> D:\Code\C#\sdkrazortest\webapp2\bin\Debug\netcoreapp3.1\webapp2.Views.dll
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:09.91
While this isn't an answer for the new templates not just working for me.. it might help someone potentially get "unstuck" or be the catalyst for someone providing a proper answer.
You need to install NuGet package Microsoft.Net.Compilers.Toolset, but make sure you match the right .NET version. In my case I was targeting netcoreapp3.1 so max version could be 4.0.1.
My root cause was for MassTransit analyzers nagging they cant find Microsoft.CodeAnalysis package, eg. An instance of analyzer MassTransit.Analyzers.AsyncMethodAnalyzer cannot be created.
I think one of the possible reasons for this issue could be the incompatibility of the .NET Framework and certain NuGet package. In my case I have .NET Core 3.1 and Testcontainers 2.4.0. The error does not happen on my local machine but it keeps showing up in my GitHub Actions remotely. It goes away after I downgrade Testcontainers to 2.3.0. Later the NuGet package AspNetCore.HealthChecks.EventStore 6.0.2 causes the same issue but that gets fixed in minutes rather than in hours :)

error APPX3212: SDK root folder for 'Portable 7.0' cannot be located

I'm trying to build my solution using TeamCity / MSBuild.
It's a WebAPI project which shares some entities in a PCL with a mobile client.
I see there are a few caveats around getting the PCL reference libraries installed on a buildserver, which I think I've sorted
(Building Portable Class Library Project in build server fails)
However, I'm getting an error during the build of the portable class library as follows:
[11:20:49][Doctrina.Pcl.Entities\Doctrina.Pcl.Entities.csproj] _GetSdkToolPaths
[11:20:49][_GetSdkToolPaths] GetSdkPropertyValue
*[11:20:49][GetSdkPropertyValue] C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\AppxPackage\Microsoft.AppXPackage.Targets(975, 5): error APPX3212: SDK root folder for 'Portable 7.0' cannot be located. See http://go.microsoft.com/fwlink/?prd=12560&pver=1.0&plcid=0x409&ar=MSDN&sar=PlatformMultiTargeting&o1=Portable&o2=7.0 for more information.*
The "help" link doesn't go anywhere useful and it seems to be very google-resistant in terms of finding any resolution.
I don't have Visual Studio 2015 installed on the build-server at all, but I have installed PortableClassLibrary tools, copied the reference directory from my local PC over, etc, as per the other related SO question.
Help please?
I encountered this error when attempting to build portable projects targeting .NET Standard.
I managed to resolve it without installing Visual Studio on my build server, by copying from a machine that does have Visual Studio installed:
C:\Program Files (x86)\Microsoft SDKs\Portable\v14.0
C:\Program Files (x86)\MSBuild\Microsoft\Portable
C:\Program Files (x86)\ReferenceAssemblies\Microsoft\Framework.NETPortable
I later attempted to build a WebApi project targeting .NET Core (this was an xproj file) and as soon as I added the XProj file to my solution, I had to also copy:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DotNet.Web
That got me a bit further but it also caused other projects to stop building properly (that were working fine without the XProj file in the solution). One thing I noticed, the NuGet tooling for .NET Core does not support authenticated NuGet feeds, so I had to enable anonymous access on my feed. But now my .NET Standard project now fails with error MSB4057: The target "_GenerateDependencyFragmentJson" does not exist in the project.
I've yet to get around to diagnosing this, but I hope the above information helps someone. If you're not using xproj files and just trying to use .NET Standard projects, the above should be all you need to build without installing Visual Studio.
Just a side note, I tried really hard to avoid having to copy these files by first trying to install Microsoft Build Tools 2015 Update 3, hoping it would put the required files in place, but it did not sadly. I'm pinning my hopes on the next version of MSBuild that is being used in VS15, and hoping that it's build tools package will have everything required to build this stuff when it comes out, as it doesn't seem like they are updating the 2015 Build Tools with this support.

the type from assembly is built with an older version of blend sdk and is not supported in a windows presentation foundation 4 project

I created a WPF project in VS 2013. After upgrading to VS 2015, this error showed in the designer on types derived from the Blend SDK:
the type from assembly is built with an older version of blend sdk and
is not supported in a windows presentation foundation 4 project
Run Command Prompt as Administrator
Change Directory to Blend SDK: cd C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.5\Libraries\
Register DLL: gacutil -i System.Windows.Interactivity.dll
Restart Visual Studio
Reference: https://connect.microsoft.com/VisualStudio/feedback/details/755407/xaml-designer-will-not-display-when-using-blend-sdk-behaviors
You can resolve this issue by manually changing the version numbers in .sln and .csproj files.
In .csproj and .csproj.user
change ToolsVersion to your current Visual Studio version. VS 2013 is version 12, VS 2015 is version 14.
In .sln change VisualStudioVersion to the current version, you can find it in the About window.
Also change Microsoft Visual Studio Solution File, Format Version to your current version (eg 14.00, 12.00)
Note: This only works for built-in assemblies. If external dependencies (like Prism) cause this error, you'd have to recompile them using the new Blend SDK. You could also try to update the dependency, maybe the newest version is already compiled using the latest Blend SDK.
None of the other answers here worked for me. What finally solved it was deleting the .NET v4.0 version of the file in the SDK folder:
C:\Program Files (x86)\Microsoft SDKs\Expression\Blend\.NETFramework\v4.0\Libraries\
I am referencing the v4.5 file via NuGet, but it seems that the designer was finding the file in the above folder. The v4.0 file was not registered in the GAC.
The popular answer is valid, but since things are always changing in the developer world, I thought I would note that there's a (IMO) better solution now.
In December 2018, Microsoft released an official, open source, supported NuGet package for XAML behaviors for WPF. (There's a separate one for UWP.) It's very easy to migrate to this package. You need to uninstall your current NuGet package, remove a couple of references, install this package, and change a using statement (or FQN).
https://www.nuget.org/packages/Microsoft.Xaml.Behaviors.Wpf/
https://devblogs.microsoft.com/dotnet/open-sourcing-xaml-behaviors-for-wpf/
I read about it in this SO answer, so credit goes to that OP:
How to add System.Windows.Interactivity to project?
Was having a similar problem using Visual Studio 2017 but none of the answers above fully resolved it for me. Found a Microsoft developer community page that had a workaround that did the trick. Comment by Bran Hagger recommended deleting the .vs folder from the solution's directory. This additional step cleared out the cache and caused Visual Studio to rebuild it.
Just the Microsoft Visual Studio Solution File, Format Version change to 14.00 worked for me.
This also could be that you are mixing different versions of System.Windows.Interactivity.dll, especially if you are getting the SDK from nuget where several different packages provide it, e.g.:
https://www.nuget.org/packages/Expression.Blend.Sdk/
https://www.nuget.org/packages/System.Windows.Interactivity.WPF/
In this case, you'll have to synchronize these libraries among projects.
Deleting the .vs file in the solution folder solved the issue. The issue happened for me after I updated My Visual Studio 2017 and Opened the project that was built before with an older version of Visual studio 2017.

Use Roslyn MSBuildWorkspace with Visual Studio 2013

For my master thesis I'm building a Visual Studio plugin that should perform some code-analysis of the current opened solution.
In order to do that I've decided to try to use Roslyn, using the corresponding nuget package.
Everything works fine (SyntaxTree for navigating the code,...) until I've tried to use MSBuildWorkspace.Create().
This last call causes the following exception:
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.":"Microsoft.Build, Version=14.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a
I found this two posts:
Creating new Microsoft.CodeAnalysis.CustomWorkspace - got ReflectionTypeLoadException
MSBuildWorkspace.Create() throws exception
from which I understand that I need the MSBuild Tools for Visual Studio 14, which is in the related iso.
I do not want to install the full Visual Studio 14, this also because the plugin that I'm writing should run under Visual Studio 2013. From the two post it seems that I can install only this part of VS 14.
My question actually is: if I install MSBuild Tools for Visual Studio 14 what will happen with all other Visual Studio projects that I'm currently working on?
At the moment they use the MSBuild tool of Visual Studio 2013. It's possible to still use that?
Update
What I'm acctually trying to get is to find if a given method has references inside the project. The idea was to proceed as in this post.
When you say you're building a plugin for Visual Studio, if all you care about is getting the workspace for the currently open solution (i.e. the code the user is editing), you shouldn't use MSBuildWorkspace, really ever. That's a type for loading things outside of Visual Studio. What you can do if you're in the product is MEF [Import] Microsoft.VisualStudio.LanguageServices.VisualStudioWorkspace. That gives you live access to what the user has open, and avoids running MSBuild entirely.
Note you're still going to have to be careful about your choice of reference assemblies you build against: if you use the latest NuGet packages that won't work since those will differ in version (and also APIs -- we changed a bunch of stuff) than what was in the last Visual Studio 2013 preview.
The issue is that (unfortunately) the assemblies in the public Roslyn nuget packages have been compiled with a newer version of MSBuild than what you want.
However, it's pretty simple to fix so that it works on MSBuild 4.0 (VS2012+). I've provided them with a PR with the fix (at https://roslyn.codeplex.com/workitem/405), but also published a nuget package called DesktopAnalysis that contains all the assemblies for doing C# code analysis, that work on VS2012+ (MSBuild 4.0+): https://www.nuget.org/packages/DesktopAnalysis
Just do an install-package DesktopAnalysis -pre instead and you're done. The assemblies are the same, the code is the same, etc.
I'm using this to provide a code migration extension that works from VS2013 all the way to VS2015 Preview.
You could fork the Roslyn codebase, and compile with MSBUILD12 defined, which should still work, though we don't really test this much.
This is entirely possible, but not at all easy.
You need to make sure that you only ever load the version of the Roslyn assemblies that is in the VS version you're targeting, by removing those assemblies from your VSIX and handling AssemblyResolve to make sure you get the right ones.
You can see my code that does exactly that here, and you can read more about this technique in my blog post
Note that if you need to [Export] any interfaces defined in Roslyn assemblies, this will not work at all, since MEF will try to load them before you add your handler. (unless you add a module initializer by hand in ildasm)
The harder part is that you need to limit yourself to the intersection of the APIs in every Roslyn version you want to support.

Categories