【问题标题】:Upgrade to Visual Studio 2010 has broken code generation - getting DirectoryNotFoundException升级到 Visual Studio 2010 已破坏代码生成 - 获取 DirectoryNotFoundException
【发布时间】:2011-04-26 12:28:08
【问题描述】:

我正在尝试将我的解决方案(一个包含大约十几个依赖程序集的 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。

【问题讨论】:

  • 你用的是什么版本的vs2010?您是否有机会使用 beta 版本?测试版中有一个类似的问题,似乎已在 RC connect.microsoft.com/VisualStudio/feedback/details/472649/… 中修复
  • 这是发布版本 - 我已经编辑了问题以反映这一点。不过,这看起来你走在正确的轨道上。 T4 生成工具未在 VS 中设置为外部工具(尽管它是外部工具)。谢谢!

标签: visual-studio-2010 code-generation


【解决方案1】:

我建议研究CodeSmith Generator,它比 T4 有很多优势,而且您不必等待很长时间来修复错误。

谢谢 -布莱克·涅米斯基

【讨论】:

    【解决方案2】:

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

    首先,模板中的第一行需要将 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-02-17
      • 2011-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多