簡體   English   中英

命名空間“System.Windows”中不存在類型或命名空間名稱“Forms”(您是否缺少程序集引用?)

[英]The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)

我正在使用 Visual Studio 2019,並且有一個控制台應用程序運行一些 selenium 測試,目標框架為 .NET 核心 3.1。 我最近添加了代碼以使用 Windows forms 在我的應用程序中上傳文件。

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 中添加引用的選項。

缺少AssemblyReferences

缺少AssemblyReferences

我嘗試將其添加為 COM 依賴項,但這也不起作用。

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

框架

構架

誰能幫我理解為什么它仍然在抱怨。

同樣,它在 Visual Studio 和命令行中本地運行良好,僅在 Teamcity 中是一個問題。 在 Teamcity 中運行的命令如下:

"C:\Program Files\dotnet\dotnet.exe" build <myTestApp>.sln @C:\BuildAgent\temp\agentTmp\a84ed99789454a3fa1f0d0028fcff404.rsp

提前致謝!

我終於從這篇文章.Net core 3:manual added framework dependencies的答案中弄清楚了。

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

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM