Powershell NuGet:如何使用Install.ps1文件将内容的“可见”设置为false?
我知道这会将CopyToOutputDirectory设置为“始终” $project.ProjectItems.Itemtest.exe.Properties.ItemCopyToOutputDirectory.Value=1 但是,当我试图以同样的方式设置可见时,它将不起作用Powershell NuGet:如何使用Install.ps1文件将内容的“可见”设置为false?,powershell,nuget,Powershell,Nuget,我知道这会将CopyToOutputDirectory设置为“始终” $project.ProjectItems.Itemtest.exe.Properties.ItemCopyToOutputDirectory.Value=1 但是,当我试图以同样的方式设置可见时,它将不起作用 $project.ProjectItems.Itemtest.exe.Properties.ItemVisible.Value=1或false或$falsetest.exe没有可见的属性项,因此无法设置该值 如果这样做
$project.ProjectItems.Itemtest.exe.Properties.ItemVisible.Value=1或false或$falsetest.exe没有可见的属性项,因此无法设置该值 如果这样做,您将得到一个错误
$project.ProjectItems.Item("Program.cs").Properties.Item("Visible")
这将起作用,因为CopyToOutputDirectory是一个实际属性
$project.ProjectItems.Item("test.exe").Properties.Item("CopyToOutputDirectory")
您可以使用Microsoft.Build.Evaluation.ProjectCollection作为替代方案,但以这种方式进行更改需要在安装包后重新加载项目
$buildProject = [Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($project.FullName)
$buildProject.Xml.AllChildren|?{$_.Include -eq "test.exe"} | % {
if ($_.HasMetadata -and ($visible=$_.Metadata|?{$_.Name -eq "Visible"}))
{
$visible.Value = $false
}
else
{
$_.AddMetadata("Visible",$false)
}
}
$buildProject.Save()
但是,它似乎阻止卸载该文件,我不确定是否在适当的时间调用Uninstall.ps1以恢复可见性,以便NuGet可以处理删除