【问题标题】:EF migration and $SolutionDir, .NetCore 2.2EF 迁移和 $SolutionDir、.NetCore 2.2
【发布时间】:2019-10-24 19:24:15
【问题描述】:

尝试在 EF 中创建初始迁移时遇到一个奇怪的错误。

我有几个项目 - 主要是 .NetStandard。 每个项目都会导入自定义 .targets 文件。只是 .csproj 文件顶部的这些行:

<Import Project="$(SolutionDir)Common.targets" />

现在,当我构建我的应用程序时,一切正常。当我运行桌面项目(使用那些 .NetStandard dll)时,一切正常。

但是当我尝试添加初始数据库迁移时,我收到如下错误:

D:\SolutionDir\ProjectDir\Project.csproj: error MSB4019: Cannot find imported project file: "D:\SolutionDir\ProjectDir\Common.targets" Make sure that the path in &lt;Import&gt; declaration is valid and the file exists.

请注意,我使用的是 $(SolutionDir),因此有效路径为:“D:\SolutionDir\Common.targets”。那他为什么要在项目目录中搜索这个文件呢?

【问题讨论】:

    标签: visual-studio .net-core entity-framework-core entity-framework-migrations


    【解决方案1】:

    好的,原来 $(SolutionDir) 仅在从 VisualStudio 编译时有效。使用其他方式(例如 dotnet 命令)构建应用程序时,$(SolutionDir) 不存在。所以唯一的方法是从项目文件中创建相对路径。

    【讨论】:

      猜你喜欢
      • 2020-04-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-23
      • 1970-01-01
      • 1970-01-01
      • 2014-02-19
      • 1970-01-01
      相关资源
      最近更新 更多