繁体   English   中英

VS2019“Post-build”脚本中的Powershell导致NullReferenceException

[英]Powershell in VS2019 “Post-build” script causes NullReferenceException

我有一个用于我的 VS2019 项目的 Powershell 脚本

Remove-Item C:\Users\me\AppData\Roaming\foo\bar

该脚本在解决方案构建的“构建后事件命令行”设置中调用。 当这条线被击中时,它只会失败:

Remove-Item : Object reference not set to an instance of an object.
1>  At C:\Users\me\source\repos\Foo\Resources\Install.ps1:17 char:1
1>  + Remove-Item C:\Users\zachd\AppData\Roaming\foo\bar
1>  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1>      + CategoryInfo          : NotSpecified: (:) [Remove-Item], NullReferenceException
1>      + FullyQualifiedErrorId : System.NullReferenceException,Microsoft.PowerShell.Commands.RemoveItemCommand
1>   
1>  Remove-Item : Object reference not set to an instance of an object.

在普通的 Windows Powershell 实例中运行完全相同的命令行没有问题,所以我只能假设这是由 VS 引起的,但我可能是错的。

你有没有尝试过

Remove-Item -Path C:\Users\me\AppData\Roaming\foo\bar

您可以尝试使用 force、recurse 删除并获取更多信息添加调试

Remove-Item -Path "location to the file/folder" -Recurse -Force -Debug

Remove-Item -Path "location to the file" -Force -Debug

一般来说,如果从任何脚本尝试它,可能需要权限。 因此,使用 force 应该可以解决Remove-Item 的此类问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM