MSBuild对Visual Studio 2017 RTM中的T4模板的支持 [英] MSBuild support for T4 templates in Visual Studio 2017 RTM

查看:99
本文介绍了MSBuild对Visual Studio 2017 RTM中的T4模板的支持的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Visual Studio 2015中,我使用的是NuGet包Unofficial.Microsoft.VisualStudio.TextTemplating.14.0.0,无论何时构建项目,该包都允许我直接从MSBuild转换T4模板.

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.

但是,在Visual Studio 2017 RTM中,这会通过以下消息破坏构建:

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'

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'

此文件由此软件包中的文件Unofficial.Microsoft.VisualStudio.TextTemplating.targets(396,5)引发.

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

我的猜测是,错误是由于环境不匹配而导致尝试使用VS 2017版本中的这些目标所致,但是我不知道如何追踪确切的问题.我目前看不到v15的更新包.

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.

如何从适用于VS 2017的MSBuild进行T4转换?会在某个时候使用NuGet的新软件包吗?还是不再支持该软件包?

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?

推荐答案

我找到了正确的解决方案.

I found the right solution.

事实证明,T4 SDK现在作为Visual Studio 2017的一部分包括在内(而不是像过去那样作为单独的Modeling SDK的一部分),但是您必须通过以下工具中的Visual Studio extension development工具集进行安装: VS2017安装程序(文本模板转换功能).

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).

安装完成后,您可以使用MSBuild通过将相关目标导入到MSBuild项目中来转换模板:

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)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
    <TransformOnBuild>True</TransformOnBuild>
    <TransformOutOfDateOnly>false</TransformOutOfDateOnly>
</PropertyGroup>

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

这解决了我的问题,并且不再需要单独的非官方NuGet软件包.

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

这篇关于MSBuild对Visual Studio 2017 RTM中的T4模板的支持的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆