nuget package uninstal ps脚本修改项目后,需要手动保存项目
当我从项目的 xml 中删除项目时,我对 nuget 卸载脚本中需要执行的操作有点困惑。首先,下面的基本脚本可以正常工作 - 它们可以正确删除我在安装脚本中添加的项目。但是,当卸载过程完成后,该项目仍然被标记为脏,必须保存。我希望当我完成后一切都得到处理。这是我得到的代码:
Import-Module (Join-Path $toolsPath msbuild.psm1)
#
# Get the project
#
$project = Get-Project
$buildProject = Get-MSBuildProject
#
# Next, add the import statements
#
$imports = $buildProject.XML.Imports | ? {([System.IO.FileInfo] $_.Project).Name -eq "LINQTargets.targets" }
if ($imports)
{
foreach ($i in $imports)
{
$buildProject.XML.RemoveChild($i)
}
}
$project.Save() #persists the changes
$buildProject.Save()
卸载 nuget 包后,我必须“保存”该项目。我怎样才能避免这种情况?我希望它保持干净状态,以便用户在卸载后无法选择不保存文件(因为这会使项目文件处于非常不一致的状态!)。
I'm a bit confused about what I need to do in a nuget uninstall script when I am removing items from the project's xml. First, the basic scripts below work - in that they correctly remove items that I'd added in the install script. But when the uninstall process finishs, the project is still marked dirty and has to be saved. I'd like that to be all taken care of when I'm done. Here is the code I've got:
Import-Module (Join-Path $toolsPath msbuild.psm1)
#
# Get the project
#
$project = Get-Project
$buildProject = Get-MSBuildProject
#
# Next, add the import statements
#
$imports = $buildProject.XML.Imports | ? {([System.IO.FileInfo] $_.Project).Name -eq "LINQTargets.targets" }
if ($imports)
{
foreach ($i in $imports)
{
$buildProject.XML.RemoveChild($i)
}
}
$project.Save() #persists the changes
$buildProject.Save()
After my nuget package has been uninstalled, I then have to "save" the project. How can I avoid that? I'd like it to be left in a clean state so the user has no option of not-saving the file after the uninstal (as that would leave the project file in a very inconsistent state!).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论