【问题标题】:The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)命名空间“System.Windows”中不存在类型或命名空间名称“Forms”(您是否缺少程序集引用?)
【发布时间】:2021-03-15 06:59:35
【问题描述】:

我正在使用 Visual Studio 2019 并且有一个控制台应用程序,它使用目标框架 .NET core 3.1 运行一些 selenium 测试。我最近添加了代码以使用 Windows 表单在我的应用程序中上传文件。

System.Windows.Forms.SendKeys.SendWait(absolutePath);
System.Windows.Forms.SendKeys.SendWait("{Enter}");

当我构建它时,我得到了以下错误: The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

所以我搜索并更新了我的项目文件以在 PropertyGroup 中添加以下两个标签:

<UseWPF>true</UseWPF>
<UseWindowsForms>true</UseWindowsForms>

欢呼,它不再在本地抱怨了。但是,当我在 Teamcity 中构建应用程序时,我得到了同样的错误。有谁知道为什么会发生这种情况。我用谷歌搜索了更多,每个人都在谈论添加程序集引用。但我没有在 Visual Studio 中添加引用的选项。

MissingAssemblyReferences

我尝试将其添加为 COM 依赖项,但也没有用。

但是,我确实看到在 Dependencies > Frameworks> System.Windows.Forms 下可用。

框架

谁能帮我理解为什么它还在抱怨。

同样,它在 Visual Studio 本地和命令行上都可以正常工作,这只是 Teamcity 中的问题。 Teamcity 中运行的命令如下:

"C:\Program Files\dotnet\dotnet.exe" build &lt;myTestApp&gt;.sln @C:\BuildAgent\temp\agentTmp\a84ed99789454a3fa1f0d0028fcff404.rsp

提前致谢!

【问题讨论】:

    标签: .net visual-studio-2019 assembly-references


    【解决方案1】:

    我终于从这篇帖子.Net core 3: manually adding framework dependencies的答案中弄清楚了。

    我必须在项目文件中包含对 Microsoft.AspNetCore.App 的框架引用,如下所示:

    <ItemGroup>
        <FrameworkReference Include="Microsoft.AspNetCore.App" />
    </ItemGroup>
    

    【讨论】:

      猜你喜欢
      • 2016-03-05
      • 2015-02-14
      • 2022-01-11
      • 2017-05-04
      • 2018-07-15
      • 2021-08-12
      • 2021-07-27
      • 2012-07-26
      相关资源
      最近更新 更多