Azure Devops 上的 Msbuild 任务:无法创建 /bin/debug,因为已存在同名文件或目录。 (MSB3021, MSB3026, MSB3027)
Msbuild Task on Azure Devops: Cannot create /bin/debug because a file or directory with the same name already exists. (MSB3021, MSB3026, MSB3027)
我是 运行 MSbuild 任务,我的解决方案(有很多项目)在 Azure Devops 上,但构建失败在一些名为 _CopyFilesMarkedCopyLocal 和(_CopyFilesMarkedCopyLocal 目标)的步骤中。
在这些步骤中,构建尝试在执行复制之前创建一个 'bin/debug' 文件夹,但这失败了,错误代码为 MSB3021、MSB3026 和 MSB3027。
这是发生此问题的日志文件的一部分。
##_CopyFilesMarkedCopyLocal:
Creating directory "bin\Debug".
Creating directory "bin\Debug".
Creating directory "bin\Debug".
Creating directory "bin\Debug
##[error]C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(4384,5): Error MSB3027: Could not copy "d:\a\s\WWSS\packages\CrystalDecisions.Windows.Forms.1.0.0\lib\CrystalDecisions.Windows.Forms.dll" to "bin\Debug\CrystalDecisions.Windows.Forms.dll". Exceeded retry count of 10. Failed.
##[d:\a\s\my\project\path\M1.csproj]
我的yaml文件内容是:
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '**/Mach1.sln'
feedsToUse: 'select'
vstsFeed: '93d16ac6-dhfjjj-43cb-89d5-e6a-41d0-b752-khf0e84jbf'
- task: MSBuild@1
inputs:
solution: '**/Mach1.sln'
msbuildArchitecture: 'x64'
platform: 'Any CPU'
configuration: 'Debug'
我搜索那些错误代码后找到的解决方案仅适用于要复制的文件被锁定的情况,而不适用于bin/debug文件夹已存在的情况。
从构建日志中,类似的_CopyFilesMarkedCopyLocal步骤在解决方案中的某些项目上成功运行但我无法解释为什么它在其他地方失败了。
即使 bin/debug 文件夹已经存在,我也需要一种方法来继续构建,但我不知道在哪里进行此设置。
下面列出了我访问过的一些链接,但none很有帮助
- Unable to copy a file from obj\Debug to bin\Debug
- Visual Studio "Could not copy" .... during build
- https://github.com/dotnet/sdk/issues/1707
I need a way to make the build continue even when the bin/debug folder
already exists but I don't know where to make this setting.
_CopyFilesMarkedCopyLocal
目标不负责创建 bin\Debug
文件夹。相反 PrepareForBuild
目标负责这样做:
所以您的问题可能是由于 PrepareForBuild
目标在 before _CopyFilesMarkedCopyLocal
目标运行时出现问题。我不确定您遇到上述信息的确切原因(调试文件夹已锁定或其中的文件已被占用?)。
作为使用上述信息的临时解决方法,您可以尝试:
1.Add msbuildArguments: '/p:OutputPath=mybin\Debug'
为了克服当前的输出路径,将构建的程序集输出到 mybin\Debug
而不是 bin\Debug
以避免 bin\Debug
时出现问题被锁定或占用。
2.Use 较新 VS build task instead of old msbuild task. As document 建议:
在尝试了这么多选项之后,最终为我解决问题的是选中 VSBuild 任务的高级选项中的 "Build in Parallel" 复选框。
我不知道为什么会修复它,但如果我知道的话,它可以节省我几天的时间。
为了确认,我还使用了 MSBuild 任务并选择了 "Build in Parallel" 选项并且构建 运行 成功并且花费了相对相同的时间。
我是 运行 MSbuild 任务,我的解决方案(有很多项目)在 Azure Devops 上,但构建失败在一些名为 _CopyFilesMarkedCopyLocal 和(_CopyFilesMarkedCopyLocal 目标)的步骤中。
在这些步骤中,构建尝试在执行复制之前创建一个 'bin/debug' 文件夹,但这失败了,错误代码为 MSB3021、MSB3026 和 MSB3027。 这是发生此问题的日志文件的一部分。
##_CopyFilesMarkedCopyLocal:
Creating directory "bin\Debug".
Creating directory "bin\Debug".
Creating directory "bin\Debug".
Creating directory "bin\Debug
##[error]C:\Program Files (x86)\Microsoft Visual Studio19\Enterprise\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets(4384,5): Error MSB3027: Could not copy "d:\a\s\WWSS\packages\CrystalDecisions.Windows.Forms.1.0.0\lib\CrystalDecisions.Windows.Forms.dll" to "bin\Debug\CrystalDecisions.Windows.Forms.dll". Exceeded retry count of 10. Failed.
##[d:\a\s\my\project\path\M1.csproj]
我的yaml文件内容是:
- task: NuGetCommand@2
inputs:
command: 'restore'
restoreSolution: '**/Mach1.sln'
feedsToUse: 'select'
vstsFeed: '93d16ac6-dhfjjj-43cb-89d5-e6a-41d0-b752-khf0e84jbf'
- task: MSBuild@1
inputs:
solution: '**/Mach1.sln'
msbuildArchitecture: 'x64'
platform: 'Any CPU'
configuration: 'Debug'
我搜索那些错误代码后找到的解决方案仅适用于要复制的文件被锁定的情况,而不适用于bin/debug文件夹已存在的情况。 从构建日志中,类似的_CopyFilesMarkedCopyLocal步骤在解决方案中的某些项目上成功运行但我无法解释为什么它在其他地方失败了。
即使 bin/debug 文件夹已经存在,我也需要一种方法来继续构建,但我不知道在哪里进行此设置。
下面列出了我访问过的一些链接,但none很有帮助
- Unable to copy a file from obj\Debug to bin\Debug
- Visual Studio "Could not copy" .... during build
- https://github.com/dotnet/sdk/issues/1707
I need a way to make the build continue even when the bin/debug folder already exists but I don't know where to make this setting.
_CopyFilesMarkedCopyLocal
目标不负责创建 bin\Debug
文件夹。相反 PrepareForBuild
目标负责这样做:
所以您的问题可能是由于 PrepareForBuild
目标在 before _CopyFilesMarkedCopyLocal
目标运行时出现问题。我不确定您遇到上述信息的确切原因(调试文件夹已锁定或其中的文件已被占用?)。
作为使用上述信息的临时解决方法,您可以尝试:
1.Add msbuildArguments: '/p:OutputPath=mybin\Debug'
为了克服当前的输出路径,将构建的程序集输出到 mybin\Debug
而不是 bin\Debug
以避免 bin\Debug
时出现问题被锁定或占用。
2.Use 较新 VS build task instead of old msbuild task. As document 建议:
在尝试了这么多选项之后,最终为我解决问题的是选中 VSBuild 任务的高级选项中的 "Build in Parallel" 复选框。
我不知道为什么会修复它,但如果我知道的话,它可以节省我几天的时间。
为了确认,我还使用了 MSBuild 任务并选择了 "Build in Parallel" 选项并且构建 运行 成功并且花费了相对相同的时间。