Sam*_*Sam 16 c# msbuild t4 visual-studio visual-studio-2017
在Visual Studio 2015中,我正在使用NuGet包Unofficial.Microsoft.VisualStudio.TextTemplating.14.0.0
,它允许我在构建项目时直接从MSBuild转换T4模板.
但是,在Visual Studio 2017 RTM中,这会使用以下消息中断构建:
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)
由此包中的文件引发的.
我的猜测是,由于环境不匹配,尝试使用VS 2017版本中的这些目标会产生错误,但我不知道如何追踪确切的问题.我可以看到v15还没有更新的包.
如何从MSBuild进行适用于VS 2017的T4变换?NuGet会有一个新的软件包在某个时候使用,还是不再支持?
Sam*_*Sam 23
我找到了正确的解决方案.
事实证明,T4 SDK现在作为Visual Studio 2017的一部分包含在内(并且不像过去那样是单独的Modeling SDK的一部分),但是您必须通过Visual Studio extension development
VS2017安装程序中的工具集进行安装(文本模板转换)特征).
安装完成后,您可以使用MSBuild通过将相关目标导入MSBuild项目来转换模板:
<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" />
Run Code Online (Sandbox Code Playgroud)
这解决了我的问题,也消除了对单独的非官方NuGet包的需求.
归档时间: |
|
查看次数: |
7433 次 |
最近记录: |