升级到Visual Studio 2010已经破坏了代码生成 - 获取DirectoryNotFoundException

时间:2010-10-17 06:26:32

标签: visual-studio-2010 code-generation

我正在尝试将我的解决方案(带有大约十几个依赖程序集的ASP.NET Web应用程序)迁移到VS 2010,并且遇到了一些新的构建错误。

Error   909 Running transformation: System.IO.DirectoryNotFoundException:
Could not find a part of the path 'c:\Program Files (x86)\Microsoft Visual Studio
10.0\Common7\IDE\SomeProject\Templates\MyTemplate.xml'.
at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)

问题非常明显 - 它正在尝试为我生成的代码加载XML,但不是查看$(SolutionDir)\ SomeProject \ Templates \ MyTemplate.xml,而是查找。\ SomeProject \ Templates \ MyTemplate.xml (其中。是Visual Studio可执行工作目录,我猜)。

幕后似乎有太多魔法,我无法找到任何定义此类的首选项或配置设置。似乎大多数生成器配置都在注册表中。

以前是否有人遇到过类似的事情?

更新:我正在运行Visual Studio 2010 Professional 10.0.30319 RTMRel。作为迁移的一部分,我还允许它将我的项目从.NET 3.5更新到.NET 4。

2 个答案:

答案 0 :(得分:1)

我知道这是一个古老的问题,但为了帮助后来可能会遇到的其他人,有两件事可以解决这个问题。

首先,模板中的第一行需要将hostspecific设置为true。

看起来应该是这样的:

<#@ template debug="false" hostspecific="true" language="C#" #>

其次,有一种更好,更可靠的方法来解析主机上的路径。

您可能有一行代码如下:

const string inputFile = @"<relative path to EDMX file>"

更好的编码方法如下:

string rootPath = Host.ResolvePath(String.Empty);
string relativePath = @"<relative path toe EDMX file>";
string inputFile = Path.Combine(rootPath, relativePath);

答案 1 :(得分:0)

我建议调查CodeSmith Generator,它比T4有很多优点,你不必等很长时间才能修复错误。

由于 -Blake Niemyjski