无法在 VS2017 上转换 T4 模板

Cannot transform T4 templates on VS2017

我已经能够在 VS2015 和 VS2017 上转换 T4 模板,直到我更换了故障计算机并安装了 only新设备上的 VS2017.

我总是得到错误:

Severity Code Description Project File Line Suppression State Error An exception was thrown while trying to compile the transformation code. The following Exception was thrown: System.IO.FileNotFoundException: Could not find file 'C:\WINDOWS\system32\Microsoft.VisualStudio.Shell'. File name: 'C:\WINDOWS\system32\Microsoft.VisualStudio.Shell' at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs, String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost) at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share) at Roslyn.Utilities.FileUtilities.OpenFileStream(String path) at Microsoft.CodeAnalysis.MetadataReference.CreateFromFile(String path, MetadataReferenceProperties properties, DocumentationProvider documentation) at Microsoft.VisualStudio.TextTemplating.CompilerBridge.<>c.<.ctor>b__15_0(String x) at System.Linq.Enumerable.WhereSelectListIterator2.MoveNext() at System.Linq.Enumerable.<UnionIterator>d__671.MoveNext() at System.Linq.Enumerable.d__671.MoveNext() at System.Linq.Buffer1..ctor(IEnumerable1 source) at System.Linq.Enumerable.ToArray[TSource](IEnumerable1 source) at System.Collections.Immutable.ImmutableArray.CreateRange[T](IEnumerable1 items) at Microsoft.CodeAnalysis.ImmutableArrayExtensions.AsImmutableOrEmpty[T](IEnumerable1 items) at Microsoft.CodeAnalysis.Compilation.ValidateReferences[T](IEnumerable1 references) at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.WithReferences(IEnumerable1 references) at Microsoft.CodeAnalysis.CSharp.CSharpCompilation.CommonWithReferences(IEnumerable1 newReferences) at Microsoft.VisualStudio.TextTemplating.CompilerBridge.PrepareNewCompilation() at Microsoft.VisualStudio.TextTemplating.CompilerBridge.Compile() at Microsoft.VisualStudio.TextTemplating.TransformationRunner.Compile(String source, String inputFile, IEnumerable1 references, Boolean debug, SupportedLanguage language, String compilerOptions) 1

我在 Visual Studio 安装程序中启用了 "Text Template Transformation"。

我尝试将 DLL 从 C:\Program Files (x86)\Microsoft Visual Studio17\Professional\Common7\IDE\PublicAssemblies 复制到 system32,但没有成功。

我也尝试用 gacutil -i 注册 DLL,但没有成功。

有什么想法吗?

原来我的一个模板引用了 Microsoft.VisualStudio.Shell

但 VS2017 仅附带一个名为 Microsoft.VisualStudio.Shell.15.0 的较新版本。

更改 .tt 中的引用后问题消失了。