Our company has legacy system that heavily relies on T4 and the employee who architected it is gone. It was running fine for us, however recently some developers upgraded to VS2015. The T4 transformations stopped working for them (with error similar as reported below). It looked at though there were references to Microsoft.VisualStudio.TextTemplating.12.0.dll. They changed the references to '14' and all worked for them. However, the same project shared by other developers on VS2013 no longer worked with error:
Compiling transformation: The type
'Microsoft.VisualStudio.TextTemplating.TextTransformation' is defined
in an assembly that is not referenced. You must add a reference to
assembly 'Microsoft.VisualStudio.TextTemplating.14.0,
Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
Are you able to run T4 on same project that is opened in both VS2013 and VS2015? One side note, there was a dependent assembly that the old employee made that all the TextTransformations derived from (it also provides helpers that are used in the *.tt files). Unfortunately it used an interface only present in Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll, so that old reference is being dragged aroundÎ. Not sure if that is contributing or not. But basically here is the bottom line:
When all devs on VS2013, everything worked and references were:
Microsoft.VisualStudio.TextTemplating.12.0.dll
Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll
Microsoft.VisualStudio.TextTemplating.VSHost.12.0.dll
Then when some went to vs2015, the only way to get it to work was to change out the 12.0* dlls with 14.0, but then vs2013 developers ceased to work.
UPDATE
I might not have clarified our complete setup. We have 20-30 *.tt files in a separate project that is included in the solution with the project that will have Text Transformations applied to it.
We have a helper Extensibility.CodeGeneration.dll (this references Microsoft.VisualStudio.TextTemplating.N.dll files as well) that have several static helpers and also base classes that derive from Microsoft.VisualStudio.TextTemplating.TextTransformation.
The 'templates' project that contains all the *.tt files, every .tt file use static methods from our helper dll. It also references all the same Microsoft.VisualStudio. dlls.
In every *.tt file, we have something that looks like this, where AreaTemplate is a class defined in the *.tt file itself and either derives from Microsoft.VisualStudio.TextTemplating.TextTransformation or one of the exposed base classes in our helper dll.
var template = new AreaTemplate { Settings = settings, Area = area, Layouts = layouts };
Write( template.TransformText() );
It was asked in comments how I obtained/used a 'host'. In searching through code we have a few common scenarios (all done inside the helper dll). In each instance, host is of type ITextTemplatingEngineHost.
Case 1:
var dte = (EnvDTE.DTE)( (IServiceProvider)host ).GetService( typeof( EnvDTE.DTE ) );
Case 2:
var hostServiceProvider = (IServiceProvider)host;
Given #3 above, I think I have to reference the Microsoft.TextTemplating dlls (and not just the Interfaces dll) due to the use/exposing of TextTransformation class.
Also, if I change references to in both my 'Helper' and 'Templates' project to 12.0...in vs2015, I get error about 'you must add reference to 12.0'...I have references to that in both applicable (in my eyes) projects...not sure why VS tells me to add it. I tried adding an explicit reference in the *.tt file using
<## assembly Name="$(ProjectDir)..\..\Assemblies\Microsoft.VisualStudio.TextTemplating.12.0.dll" #>
But then I got the error
The type 'Microsoft.VisualStudio.TextTemplating.TextTransformation'
exists in both
'c:\BTR\Source\Assemblies\Microsoft.VisualStudio.TextTemplating.12.0.dll'
and
'c:\Windows\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating.14.0\v4.0_14.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.TextTemplating.14.0.dll'
It is almost like there is a hidden/implicit reference to the latest Texttemplating already built into VS??
Not sure if our setup was a more complicated way to achieve our original goal, but I don't think I'll be able to unwind it and change if we are doing it the incorrect way.
Given our setup let me know if you think I am stuck or not. I was trying to figure out 'conditions' in MSBuild to help support both Visual Studios but couldn't succeed.
Thanks in advance.
Try changing the reference from "Microsoft.VisualStudio.TextTemplating.12.0.dll" to "Microsoft.VisualStudio.TextTemplating.Interfaces.12.0.dll". Each new version of Visual Studio services will have a new implementation assembly that will implement the previous versions interfaces. To maintain backward compatibility, you should only reference the interface assemblies and not the implementation assemblies. You might have to change the templates if they reference anything not in the interface.
Updated
Wow, so you have a pretty complicated setup and I don't know if you will be able to use it in both versions without changing the code like you did.
I think the main problem is in your helper class, in #3 you said that the AreaTemplate class derives from TextTransformation. TextTransformation is in the implementation dll so it will exist in each version of visual studio. If you helper dll is complied to reference it from 2013 and then you use that dll in 2015 it will not work.
When a T4 template is transformed, the text in the file is parsed into a class, that class is loaded into an app domain(separate from the one visual studio is running in) and the class's TransformText method is called. Since your templates reference your helper class, the helper assembly will be loaded into the new app domain, which will in turn try to load TextTemplating 12 in there too, the app domain will not be able to resolve the 12 reference because you are using VS 2015.
In the other direction when you reference text templating 14 from 2015 and try to use it in VS 2013 you will have the same problem, the app domain will not be able to find TextTemplating 14 because you are in VS 2013 and the 14 dll does not exist.
In the last scenario when you are in VS 2015 and your add a link to TextTemplating 12 in your tt files it is failing because the app domain created to run the template has already loaded the TextTemplating 14 dll then you also tell it to load the TextTemplating 12 dll. This goes back to my posts in the comments when I talked about VS backward compatibility, TextTemplating 12 and 14 have the same TextTransformation class in the same namespace and the runtime can't load them both so you get that error.
Few things you can try:
1) Put the TextTemplating 12 dll in the GAC on the VS 2015 machines. In theory, this will let the T4 AppDomain load both copies of TextTemplating and then VS 2015 would be able to use the 14 version while your tt files and helper dll use the 12 version. Leave the VS 2013 machines the same.
2) Do the same as 1 but in reverse, setup the projects to target 2015 and reference the 14 dll then on the vs 2013 machines GAC the 14 dll, not sure if this will work since the 14 dll might have other dependencies on newer vs assemblies.
3) On the vs 2015 machines figure out a way to do binding redirects for the T4 App Domain so that calls looking to TextTemplating 12 would be resolved to TextTemplating 14. Usually binding redirects are done in the app/web.config files but not sure how you would do them for T4, may have to peek at the code and see how the app domain is created and loaded.
I have faced the same problem and I think I have a solution, which works - use the VisualStudioVersion msbuild property to reference the right version of the assemblies. Something like this:
<Reference Include="Microsoft.VisualStudio.TextTemplating.$(VisualStudioVersion)">
<HintPath>..\Dependencies\Microsoft.VisualStudio.TextTemplating.$(VisualStudioVersion).dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TextTemplating.Interfaces.10.0">
<HintPath>..\Dependencies\Microsoft.VisualStudio.TextTemplating.Interfaces.10.0.dll</HintPath>
</Reference>
Make sure the Dependencies folder has both Microsoft.VisualStudio.TextTemplating.12.0.dll and Microsoft.VisualStudio.TextTemplating.14.0.dll.
Seems to work.
We have a very similar scenario to yours, just a bit more complex because our T4 templates depend on a couple of DSL-Tools packages.
I’ve made some tests and in fact the solution for this problem is to remove any reference to Microsoft.VisualStudio.TextTemplating.12.0 and keep the references to the Interfaces assemblies. Exactly as pointed by Frank. This would make the projects and the templates compatible with both Visual Studio 2013 and 2015.
Unfortunately this doesn’t help in our scenario because DSL-tools projects require references to Microsoft.VisualStudio.TextTemplating.12.0 or Microsoft.VisualStudio.TextTemplating.14.0 because the DirectiveProcessor.tt template generates a class that derives from RequiresProvidesDirectiveProcessor, an abstract class that resides in one of those assemblies (depending on the version of Visual Studio you would want to compile the DSL-tools project with).
I suppose that is one of the reasons why DSL-tools projects are upgraded when you open them with higher Visual Studio versions… But that is a pain because it forces large teams like ours to upgrade Visual Studio all at the same time.
Related
When I try to use an extension method in the Immediate or Watch windows, I get the following error:
{method} is not a member of {class}
I'm using Visual Studio Community 2013 Update 4, but the issue exists on multiple PCs here, running varying versions of Visual Studio 2013 and 2015.
It makes no difference whether the extension methods come from the .NET BCL, or are defined in our project. The code itself compiles and runs successfully; the issue is only in Immediate and Watch.
I tried setting all projects to framework 4.5.1, and using the x86 configuration, without result.
Adding Imports System.Linq at the beginning of the code file makes no difference (which makes sense, as System.Linq is already globally imported (Project properties -> References -> Imported namespaces)).
What else can be done?
In any context where System.Linq isn't imported you can call the extension methods as normal static methods instead. So for example, the following did not work for me in the QuickWatch window (where actualVariables is a List):
actualVariables.Select(x=>x.Identity.DisplayName)
Change it to this form and then it works:
System.Linq.Enumerable.Select(actualVariables,x=>x.Identity.DisplayName)
I am trying to convert a SharePoint 2010 solution (custom web parts, content types, lists, event receivers, etc.) developed in Visual Studio 2010 to SharePoint 2013 and Visual Studio 2012. When I open the project in VS 2012, it converts a couple of the project files but won't compile because of reference issues.
I copied the DLLs (mostly Microsoft.SharePoint..., although I needed to copy the Microsoft.Office.SecureStoreService.dll too) that were causing issues from my 2010 server to the 2013 server and fixed the references. However, the Microsoft.Office.SecureStoreService.dll still gives me compiler errors claiming "Error 203 The type or namespace name 'Office' does not exist in the namespace 'Microsoft' (are you missing an assembly reference?)" when visual studio has no problem with the namespace and finds the SecureStoreProvider class inside it just fine.
I've also tried to change the target framework from 3.5 to 4 and only see "Install other frameworks..." in the target framework dropdown.
I'm sure that others have dealt with this, but have been unsuccessful in framing the right google search query. I'm relatively new to SharePoint in general and any help would be appreciated.
thanks,
Mike
I was able to get my solution upgraded from a 2010 project to 2013 using the following. Note that this will update your solution to use the new 2013 API. It is possible to update just the project file but still run in 2010 mode.
First edit your .csproj file (for c#).
Modify the target framework to this:
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
Add this a node for the office version, I put mine directly below the TargetFrameworkVersion tag
<TargetOfficeVersion>15.0</TargetOfficeVersion>
Update references
Reload the project and update your referenced assemblies. If you haven't specified a specific version they should already be referencing the v15 (SharePoint 2013) assemblies.
Do a find replace for 14.0.0.0 to 15.0.0.0. This updates any references on your pages, layouts, and master pages to the v15 assemblies.
Change calls
Change any calls to SPUtility.GetGenericSetupPath() to SPUtility.GetVersionedGenericSetupPath()
Check each file to do a check for any hive references. You'll need to add a /15/ to these. EG: _layouts/ to _layouts/15/
Open the package "folder" in visual studio then update the properties for that package to use version 15.
Clean up
Finally do a compile clean up any missed items. Deploy your solution and make sure to test thoroughly.
I am using Visual Studio Professional 2010 and the Team Foundation Server Express (beta). My VS Project (C#.Net / WPF) has been migrated from VS 2008 (without TFS) to VS 2010 (with TFS).
Whenever I apply changes to my code and try to debug my application, I get messages like This breakpoint will not be hit. (in german: Der Haltepunkt wird momentan nicht erreicht. Der Quellcode weist Unterschiede zur Originalversion auf.) and the project is started using the old executable version (the one with the last successful build). No errors occure, the code is OK, but the changes are not applied either.
When I manually cleanup and rebuild my project, everything works quite fine - but there has to be a fix for this issue?
Edit: I just added a new project to my VS solution and checked it in on the TFS Server. Using this new project the problem does not occure. Even when I add the same dependencies I used in the project mentioned above, the debugging and building of the new project works fine without the errors mentioned above.
Maybe this information helps you to lead me to a solution.
It's not clear whether existing answers are not sufficient. I can't know exactly what's causing your problem; but, I can detail some places this potentially comes up.
The first area that I commonly see this is when a project references an assembly directly. You can create a project that creates an assembly. Another project might use that assembly and you can reference by assembly directly (and not add a reference to the "project"). This disconnects VS from really knowing it needs to "build" that referenced assembly first and it will sometimes get out of sync with the debugging symbols (PDB). You can tell if a project has been referenced or an assembly has been referenced in the properties of the reference (expand References in Solution Explorer, right-click a reference, and select Properties). A referenced project will not have a Specific Version property, while an assembly reference will. You can sometimes also tell from Project\Project Dependencies. If you have a reference to an assembly generated by another project but that project isn't a dependency in Project Dependencies, it might be an assembly reference. To fix this, you can usually just delete the reference and add a reference to the project.
I've also find that sometimes breakpoints confuses the debugger. If I have many breakpoints or they've been kicking around a long time, the debugger sometimes does some weird things. If I delete all the existing break points (Debug/Delete all breakpoints) and re-apply them the debugger is usually much happier.
You can find the answer here. The assemblies might be in GAC or a project or some projects need to be rebuild to generate the pdb files again, which are used for debugging. If you don't choose to rebuild it might use the old pdb files.
My guess is that you are putting breaking points somewhere your program can't access them.
Ex:
const int x = 5;
if(this.x == 1)
//do sth <--- breakpoint here
If you are running a mixed mode application (unmanaged native C++ & managed C#), make sure to set Enable unmanaged code debugging in your C# application's Properties window.
You have to rebuild, there isn't an easier way around it.
The program database files (PDB) need to be recreated. You should also have your configuration setting set to debug.
Also the first answer to this question must be of help as well.
This happened to me when I started VS as an admin, and it also happened to me when the project is set to a different architecture than a DLL that I used in this project.
I wrote a control library using visual studio 2010, I'll call it MyLibrary. MyLibrary references another control library I have that we'll call AnotherLibrary. I also have a clean virtual machine (CVM) and I've added AnotherLibrary to the GAC on the CVM. Using the CVM, I create a new WinForms project, add MyLibrary.dll to the toolbox, and drop one of the controls onto the form. Visual Studio will add MyLibrary.dll AND AnotherLibrary.dll to the references, even though AnotherLibrary.dll is in the GAC (and isn't needed). I can remove AnotherLibrary.dll from the references and everything is fine.
Is there a way to prevent visual studio from adding AnotherLibrary.dll in this scenario?
Edit: I've given this some thought and I have an example. When you add a TabControl to a parent control in the designer, visual studio won't add System.Design to the references, even though the TabControl depends on it. So, surely there is a way to do this?
You still need the reference. Just like you need the reference to, say, System.dll which is also in the GAC. You just don't need the copy of the assembly in your bin\Debug directory. That you happened to not break the compiler by removing the reference is possible, especially since is this is an indirectly used assembly. But some odds that you'll eventually run out of luck.
In general you really want to avoid using the GAC on your dev machine. Because you care about specific versions of an assembly when you, say, create a bug fix. You get those specific versions from source control, not the GAC.
Doesn't it make sense that it would automatically include all dependencies? It cannot assume that AnotherLibrary is in the GAC on every machine you might want to deploy your code on. Of course as you mentioned you can manually remove it....
Here's a puzzler - something that doesn't work that I assumed would (no surprise there).
We have a library project that is referenced in a few other desktop app projects. The library project is written in VS 2005 (.NET 2.0).
My problem is that some of our apps still live in VS 2005 for the time being (for various reason). I can't seem to reference this library project in VS 2010 without it demanding that I upgrade it to .NET 4, which if I do, then breaks my ability to include it as a reference in my VS 2005 projects.
This type of thing fries my brain. Is there any way I can make this work?
Hmm, that doesn't make a lot of sense. You don't reference a 'library project', you reference the DLL that it produces. Project + Add Reference, Browse tab. There's no known problem with that, within a 95% accuracy guess, mixed mode assemblies have a few hairs.
If you actually try to load a vs2005 project into a vs2010 solution, then yes, it's going to try to convert the project file. And that turns vs2005 catatonic, it doesn't have the time machine to guess what a vs2010 project looks like. Just making a copy of the project directory solves that problem.
Can you change the .NET version back to 3.5 or 2.0 in VS.NET 2010 after it revises the project version to .NET 4.0?
Use a file reference to the built dll, rather than a project reference.
You may also find you need to add an extra bit of compatible-framework info to your manifest file to tell .net to allow your .exe to use .net 4 and .net 2 assemblies alongside each other - if it's not there you'll just get an error on startup. (Sorry, I can't remember the exact details and I'm not at my work machine right now to be able to find them - but if you have problems at runtime, the error message should lead you to the exact solution you need)
Correction: I was thinking of this 'useLegacy' startup setting, which you may need to add to your app.config if you want to use a mixture of .net 2.0 and .net 4.0 assemblies in your application:
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
On option, that is a complete PITA, but should work is:
Create a new project file in 2010 that includes everything the 2005 project file has. Just call it MyProject2010.csproj or whatever.
Then, add this project to your 2010 solution.