0

我很困惑。我有一个 WPF 解决方案,其中我将各种视图拆分为单独的项目。我还有一个自定义控件的项目。最后,我的应用程序在另一个项目中,设置为默认项目。

我的主窗口和其他视图之一都使用自定义控件项目中的控件。除了使用自定义控件的第二个视图之外,我的所有项目都成功构建。

我无法在示例应用程序中复制此内容,但我会尽我所能在此处进行说明。

MySolution
    MyApp.csproj
       References
           MyMainWindow
           MySecondWindow
           MyThirdWindow
           MyViewModels
           [std WPF references]
       App.xaml
           App.xaml.cs
    MyMainWindow.csproj
       References
           MyControls
           [std WPF references]
       MainWindow.xaml
           MainWindow.xaml.cs
    MySecondWindow.csproj
       References
           [std WPF references]
       SecondWindow.xaml
           SecondWindow.xaml.cs
    MyThirdWindow.csproj
       References
           MyControls
           [std WPF references]
       ThirdWindow.xaml
           ThirdWindow.xaml.cs
    MyControls
       References
           [std WPF references]
       ControlForMainWindow.xaml
           ControlForMainWindow.xaml.cs
       ControlForThirdWindow.xaml
           ControlForThirdWindow.xaml.cs

在这个(非常粗略的)示例中,MyMainWindow 项目和 MyThirdWindow 项目的引用相同。除 MyThirdWindow 之外的每个项目都成功构建。我得到的错误是:

Could not load file or assembly '[MyControls]' or one of its dependencies.
The system cannot find the file specified.

有谁知道当一个看似相同的项目失败时,为什么会建立一个项目?

编辑1:

如果我从 MyThirdWindow 中删除 ControlForThirdWindow(和命名空间声明)(但保留项目引用),则整个解决方案都会构建并且应用程序会运行,即使 MyMainWindow 仍然使用 ControlForMainWindow。我已经验证命名空间声明是正确的(我从 MyMainWindow 复制了它)

4

1 回答 1

0

我一直在致力于将所有窗口移动到单独的项目中。对于每个窗口,这需要几个步骤:

  • 创建一个新项目
  • 将窗口代码复制到新项目中
  • 更新副本中的命名空间
  • 从应用程序项目中删除窗口代码
  • using在应用程序项目中添加对新项目的引用(和语句)
  • 如有必要,在新项目中添加对依赖项的引用
  • 更新目标框架

显然 MyControls 上的目标框架设置为 .NET Framework 4,而 MyThirdWindow 设置为 .NET Framework 4 Client Profile。我已经在我所有的其他窗口项目上设置了它,只是错过了这个。

解决方案现在构建良好。

于 2012-12-13T13:17:31.723 回答