在开发模式下使用自定义 MSBuild 任务时的文件锁定问题

问题描述 投票:0回答:1

我正在按照“Microsoft 示例”中概述的指导开发自定义 MSBuild 任务。开发工作流程不好,因为每当我更改任务并且想要测试它时,我都需要重新启动 VS(我正在使用 <UsingTask> 在另一个项目中引用它来测试该任务)。

我将建议的代码片段复制到我的

MSBuildConsoleExample.csproj

文件中,并且文件已成功生成。

但是,在对

AppSettingStronglyTyped

项目中的任务实现进行修改后,我在构建过程中遇到了错误。具体错误信息如下:

Severity    Code    Description Project File    Line    Suppression State
Warning MSB3026 Could not copy "obj\Debug\netstandard2.0\AppSettingStronglyTyped.dll" to "bin\Debug\netstandard2.0\AppSettingStronglyTyped.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'bin\Debug\netstandard2.0\AppSettingStronglyTyped.dll' because it is being used by another process. The file is locked by: "MSBuild.exe (760)" AppSettingStronglyTyped D:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64\Microsoft.Common.CurrentVersion.targets    4734

此问题严重阻碍本地测试和开发,每次进行更改时都需要重新启动 Visual Studio。我正在寻求指导或潜在的解决方案来克服此文件锁定问题,以促进更顺利的本地开发。

作为参考,可以访问相关代码片段

这里

当前解决方法

目前,为了解决文件锁定问题,我采取了一种解决方法:重新启动 Visual Studio,重建

AppSettingStronglyTyped

,然后重建

MSBuildConsoleExample
理想情况下,预期行为将允许在 
AppSettingStronglyTyped

内无缝更新生成的文件,而无需重新启动 Visual Studio。这样,在

AppSettingStronglyTyped

 中所做的更改将反映在 
MSBuildConsoleExample
 中,而无需完全重新启动开发环境。
尝试使用本地 Nuget 包

为了缓解该问题,我尝试使用本地 NuGet 源并在每次构建迭代时生成新的 NuGet 包。然而,这种方法暴露了 Visual Studio 缓存问题。需要大约 3 分钟的等待时间才能更新 NuGet 缓存,或者需要重新打开 Visual Studio 才能解决缓存问题。

Visual Studio 包含一个工具包,如果你尝试重新启动它,步骤会非常慢。
visual-studio msbuild nuget-package msbuild-task
1个回答
0
投票
由于情况是msbuild锁定了文件,你可以直接杀掉msbuild。

打开任务管理器,然后结束msbuild任务以释放文件。

这种方式应该比你现在做的更快。

© www.soinside.com 2019 - 2024. All rights reserved.