Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In Visual Studio 2015, I'm using the NuGet package Unofficial.Microsoft.VisualStudio.TextTemplating.14.0.0 which allows me to transform T4 templates directly from MSBuild, whenever a project is built.

In Visual Studio 2017 RTM however, this breaks the build with the following messages:

An Exception was thrown while running the transformation code. The process cannot continue. The following Exception was thrown: System.IO.FileNotFoundException: 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. File name: 'Microsoft.CodeAnalysis, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

This is raised by the file Unofficial.Microsoft.VisualStudio.TextTemplating.targets(396,5) which is in this package.

My guess is that the error comes from trying to use these targets from a VS 2017 build due to mismatched environments, but I don't know how to trace the exact issue. There is no updated package yet for v15 that I can see.

How can I do T4 transforms from MSBuild that will work for VS 2017? Will there be a new package from NuGet to use at some point or is this not going to be supported anymore?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
453 views
Welcome To Ask or Share your Answers For Others

1 Answer

I found the right solution.

Turns out that the T4 SDK is now included as part of Visual Studio 2017 (and not part of the separate Modeling SDK as it has been in the past), BUT you have to install it via the Visual Studio extension development toolset in the VS2017 installer (Text Template Transformation feature).

Once this is installed, you can use MSBuild to transform templates by importing the relevant targets into the MSBuild project:

<PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">15.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)MicrosoftVisualStudiov$(VisualStudioVersion)</VSToolsPath>
    <TransformOnBuild>True</TransformOnBuild>
    <TransformOutOfDateOnly>false</TransformOutOfDateOnly>
</PropertyGroup>

<!-- add AFTER import for $(MSBuildToolsPath)Microsoft.CSharp.targets -->
<Import Project="$(VSToolsPath)TextTemplatingMicrosoft.TextTemplating.targets" />

This solved my problem and also removes the need for the separate unofficial NuGet package.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...