删除文件夹&使用 NuGet/Powershell 来自项目的文件

发布于 2024-11-03 06:54:55 字数 958 浏览 0 评论 0原文

我试图在 NuGet 包安装期间从项目中删除 App_Start 文件夹。 NuGet 的文档位于:

http://nuget.codeplex.com/wikipage?title=Creating%20a% 20Package

说:

$project.Object 相当于 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 认为这些项目是项目的一部分。

我需要的是一种以编程方式从项目中删除对这些项目的引用的方法。有什么想法吗?

I am trying to remove the App_Start folder from my project during my NuGet package install. The documentation for NuGet here:

http://nuget.codeplex.com/wikipage?title=Creating%20a%20Package

Says:

$project.Object is the equivalent of http://msdn.microsoft.com/en-us/library/ms170626.aspx.

Which I am not able to find much information of that interface that is of much help to me.

I have the following Powershell script which successfully removes the folder and files:

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

(I know the pathing here isn't guaranteed, but this package is for internal use only)

But the project still has a reference to the items and therefore the items appear with the yellow warning because Visual Studio believes that the items are part of the project.

What I need is a way to remove a reference to those items from the project programatically. Any ideas?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一抹苦笑 2024-11-10 06:54:55

好吧,我绝对确定有比这更好的方法,但直到今天我才使用过 NuGet 或 Powershell...:/

我刚刚在我的包管理器控制台中运行了这个:

$DTE.Solution.Projects | ForEach { $_.ProjectItems | ForEach { if ($_.Name -eq "Controllers") { $_.Remove() } } }

它循环遍历所有项目项,寻找顶部- 级别项目称为“控制器”,然后将其从项目中删除。很确定您可以将其更改为“App_Code”。

编辑:我的朋友(他比我更了解 Powershell)发送了以下内容:

$DTE.Solution.Projects|Select-Object -Expand ProjectItems|Where-Object{$_.Name -eq 'Controllers'}|ForEach-Object{$_.Remove()}

Ok, I'm absolutely sure there's a better way than this, but I've never used NuGet or Powershell until today... :/

I just ran this in my Package Manager Console:

$DTE.Solution.Projects | ForEach { $_.ProjectItems | ForEach { if ($_.Name -eq "Controllers") { $_.Remove() } } }

It looped through all projects items looking for a top-level item called "Controllers" and then removed it from the project. Pretty sure you could just change this to "App_Code".

Edit: Friend of mine (who knows a little more Powershell than me) sent this:

$DTE.Solution.Projects|Select-Object -Expand ProjectItems|Where-Object{$_.Name -eq 'Controllers'}|ForEach-Object{$_.Remove()}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文