错误 MSB3030 无法复制文件 "C:\Users\...\WebApi3\obj\Debug\netcoreapp3.0\webapi3.exe" 因为找不到

Error MSB3030 Could not copy the file "C:\Users\...\WebApi3\obj\Debug\netcoreapp3.0\webapi3.exe" because it was not found

嗨,Whosebug 社区,

我正在尝试使用 Target Framework - .NET Core 3.0 构建我的 Web 和 WebAPI 控制台应用程序,根据项目 'Application' 属性,使用:

Microsoft Visual Studio 社区 2019 Windows 10 PRO

上的版本 16.5.4

我看到以下错误:

错误 MSB3030 无法复制文件 "C:\Users...\WebApi3\obj\Debug\netcoreapp3.0\webapi3.exe" 因为找不到

错误 MSB3030 无法复制文件 "C:\Users...\Web\obj\Debug\netcoreapp3.0\webportal.exe" 因为找不到

因此这些项目没有得到建设。

感谢您花时间阅读本文。

请指教

这是错误指向的代码部分:

    ============================================================
                                        _CopyOutOfDateSourceItemsToOutputDirectory

    Copy files that have the CopyToOutputDirectory attribute set to 'PreserveNewest'.
    ============================================================
    -->
  <Target
      Name="_CopyOutOfDateSourceItemsToOutputDirectory"
      Condition=" '@(_SourceItemsToCopyToOutputDirectory)' != '' "
      Inputs="@(_SourceItemsToCopyToOutputDirectory)"
      Outputs="@(_SourceItemsToCopyToOutputDirectory->'$(OutDir)%(TargetPath)')">

    <!--
        Not using SkipUnchangedFiles="true" because the application may want to change
        one of these files and not have an incremental build replace it.
        -->
    <Copy
        SourceFiles = "@(_SourceItemsToCopyToOutputDirectory)"
        DestinationFiles = "@(_SourceItemsToCopyToOutputDirectory->'$(OutDir)%(TargetPath)')"
        OverwriteReadOnlyFiles="$(OverwriteReadOnlyFiles)"
        Retries="$(CopyRetryCount)"
        RetryDelayMilliseconds="$(CopyRetryDelayMilliseconds)"
        UseHardlinksIfPossible="$(CreateHardLinksForAdditionalFilesIfPossible)"
        UseSymboliclinksIfPossible="$(CreateSymbolicLinksForAdditionalFilesIfPossible)"
            >

      <Output TaskParameter="DestinationFiles" ItemName="FileWrites"/>

    </Copy>

  </Target>

正在将 Visual Studio 更新到 16.5.5。到目前为止似乎已经解决了这个问题。

我在尝试发布时遇到了类似的问题。受影响的 .DLL 是一个 nuget 包,我注意到我有一个更新。

更新受影响的包、清理解决方案、重建然后重新发布解决了我的问题。

我在 VS2022(17.0.1) 中也遇到了同样的问题。我根据 github 问题 [https://github.com/dotnet/sdk/issues/3122] 的讨论执行了以下步骤,我的问题得到了解决。我相信这也适用于 VS2019。

第 1 步:清理本地 Nuget 缓存 ..\projectDir> dotnet nuget locals all --clear

第 2 步:删除 bin 和 Obj 文件夹 ..\projectDir> rd \s \q bin obj

第 3 步:使用 Visual studio 构建菜单

清理解决方案

第四步:重建项目

对于 CoreXT 存储库,默认情况下仅收集零售版本的 obj 或调试版本的 objd 下的输出。您似乎正在使用零售桥并使用 obj(Debug|Release) 和 bin(MSBuild non-CoreXT 默认值),因此未收集这些输出。

为了解决这个问题,您可以设置 -UsePredictedOutputPath QuickBuild 标志,这将避免收集那些 hard-coded 路径,而是询问每个项目它的 $(IntermediateOutputPath) 和$(OutputPath) 是并使用它们。

请注意,无论哪种情况,始终会收集输出根目录(例如 /target)下的输出。此标志仅影响 project-relative 输出。