我正在尝试在 NuGet 包安装期间从我的项目中删除 App_Start 文件夹。 NuGet 的文档在这里:
http://nuget.codeplex.com/wikipage?title=Creating%20a%20Package
说:
$project.Object is the equivalent of http://msdn.microsoft.com/en-us/library/ms170626.aspx.
我无法找到该界面的很多信息,这对我有很大帮助。
我有以下成功的 Powershell 脚本 删除 文件夹和文件:
param($installPath, $toolsPath, $package, $project)
$DirInfo = New-Object System.IO.DirectoryInfo($installPath)
$appDir = New-Object System.IO.DirectoryInfo($DirInfo.Parent.Parent.FullName)
$fullPath = [IO.Path]::Combine($appDir.FullName, $appDir.Name, "App_start")
Remove-Item $fullPath -recurse
(我知道这里的路径不能保证,但这个包仅供内部使用)
但是项目仍然引用了这些项目,因此这些项目显示为黄色警告,因为 Visual Studio 认为这些项目是项目的一部分。
我需要的是一种以编程方式从项目中删除对这些项目的引用的方法。有任何想法吗?
最佳答案
好的,我绝对确定有比这更好的方法,但直到今天我才使用过 NuGet 或 Powershell...:/
我刚刚在我的包管理器控制台中运行了这个:
$DTE.Solution.Projects | ForEach { $_.ProjectItems | ForEach { if ($_.Name -eq "Controllers") { $_.Remove() } } }
它遍历所有项目项,寻找名为“ Controller ”的顶级项,然后将其从项目中删除。很确定您可以将其更改为“App_Code”。
编辑:我的 friend (谁比我更了解 Powershell)发送了这个:
$DTE.Solution.Projects|Select-Object -Expand ProjectItems|Where-Object{$_.Name -eq 'Controllers'}|ForEach-Object{$_.Remove()}
关于powershell - 使用 NuGet/Powershell 从项目中删除文件夹和文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5790767/