我走了VS2010的後面,並刪除了一個圖像文件夾中的一些圖像,該圖像文件夾被Web項目引用爲內容。在解決方案導航器中,這些文件現在顯示黃色警告圖標,表明無法找到該文件。刷新文件夾不起作用。有沒有辦法告訴VS2010自動同步文件夾? VS網站項目默認執行此操作。刪除VS2010對Web項目中刪除的文件的引用
回答
在Visual Studio中,找到丟失的文件,選擇它們並按del
(或右鍵單擊並選擇Delete
)。
保存該項目,你很好去。
如您所述,這不是自動的 - 項目文件需要與實際文件系統同步。這不會發生在網站「項目」上,因爲沒有項目文件。
我希望不必這樣做,但那就是生活。 – 2012-02-08 06:48:14
我希望不必這樣做,但那是活的,不幸的是在新的Visual Studio 2013中。下一次:總是從項目/解決方案中刪除,而不是直接在文件資源管理器中... – Langeleppel 2013-12-05 14:16:32
in vs 2015(not確定有關舊版本),項目樹上方有一個搜索欄,您可以使用該搜索欄進行過濾,然後多選並點擊刪除一次。儘管只有在你需要刪除的所有文件都被命名爲 – agradl 2015-05-07 19:22:03
我剛剛在VS 2015中遇到了這個問題。文件在web項目中缺失,所以不想去尋找它們。
回家的捷徑是:排除所有文件/文件夾然後將它們包括所有一次。
即:
- 解決方案資源管理器 - >選擇所有文件和文件夾 - >右鍵 - > 「從計劃中排除」
- 解決方案資源管理器 - >點擊 「顯示所有文件」
- 解決方案資源管理器 - >選擇所有文件和文件夾 - >右鍵單擊 - >「包含在項目中」
時,這纔有效。請注意,這種方法的缺點是,您還將包含以前明確排除的文件。 – Chris 2016-05-24 12:59:45
我已經創建了一個PowerShell腳本來處理這個問題。
function ExtractInclude ($line)
{
if ($line -like '*Content Include=*') {
return $line.Split('"') | select -Skip 1 | select -First 1
}
}
function RemoveMissingInclude ([string]$path, [bool]$report) {
$reader = [System.IO.File]::OpenText($path)
$projectPath = (Split-Path $path) + "/"
try {
for() {
$line = $reader.ReadLine()
if ($line -eq $null) { break }
$pathInclude = ExtractInclude($line)
if ($report) {
if ($pathInclude -ne "") {
if (-not (Test-Path "$projectPath$pathInclude")) { $pathInclude }
}
} else {
if ($pathInclude -ne "") {
if (Test-Path "$projectPath$pathInclude") { $line }
} else {
$line
}
}
}
}
finally {
$reader.Close()
}
}
只要運行以下命令,創建一個清理項目文件:
RemoveMissingInclude -path "D:\path\name.csproj" | Out-File D:\path\nameClean.csproj
的更多信息,這篇博客文章中找到:http://devslice.net/2017/06/remove-missing-references-visual-studio/
這很好,但沒有考慮到「
我做了一個非常簡單的控制檯應用程序此:
using System;
using System.IO;
using System.Collections.Generic;
namespace CleanProject
{
class Program
{
static void Main(string[] args)
{
var newFile = new List<string>();
if (args.Length == 0)
{
Console.WriteLine("Please specify the project full path as an argument");
return;
}
var projFile = args[0];
if (!File.Exists(projFile))
{
Console.WriteLine("The specified project file does not exist: {0}", projFile);
return;
}
if (!projFile.ToLowerInvariant().EndsWith(".csproj"))
{
Console.WriteLine("The specified does not seem to be a project file: {0}", projFile);
return;
}
Console.WriteLine("Started removing missing files from project:", projFile);
var newProjFile = Path.Combine(Path.GetDirectoryName(projFile), Path.GetFileNameWithoutExtension(projFile) + ".Clean.csproj");
var lines = File.ReadAllLines(projFile);
var projectPath = Path.GetDirectoryName(projFile);
for(var i = 0; i < lines.Length; i++)
{
var line = lines[i];
if (!line.Contains("<Content Include=\"") && !line.Contains("<None Include=\""))
{
newFile.Add(line);
}
else
{
var start = line.IndexOf("Include=\"") + "Include=\"".Length;
var end = line.LastIndexOf("\"");
var path = line.Substring(start, end - start);
if (File.Exists(Path.Combine(projectPath, path)))
{
newFile.Add(line);
}
else
{
if (!line.EndsWith("/>")) // I'm assuming it's only one line inside the tag
i += 2;
}
}
}
File.WriteAllLines(newProjFile, newFile);
Console.WriteLine("Finished removing missing files from project.");
Console.WriteLine("Cleaned project file: {0}", newProjFile);
}
}
}
- 1. 從web項目中刪除dal引用
- 2. Web安裝項目從VS2008升級到VS2010後刪除文件
- 3. 刪除,項目不能刪除文件
- 4. 刪除VBA項目引用
- 5. 刪除csv文件中的項目?
- 6. 爲什麼VS2010刪除我的引用?
- 7. 刪除Web目錄之外的文件?
- 8. 從項目中刪除未引用的文件
- 9. 如何永久刪除Textmate項目中的文件引用?
- 10. Unity3D在MonoDevelop中刪除項目引用
- 11. 刪除-項目Vs的[有System.IO.File] ::刪除()
- 12. 如何刪除項目刪除時的「,」?
- 13. PowerShell中刪除,項目不能刪除填充文件夾
- 14. 在TFS中刪除項目時刪除本地文件夾?
- 15. 刪除的項目
- 16. 無法使用刪除項目。刪除
- 17. 刪除項目
- 18. 刪除項目
- 19. 刪除項目
- 20. 刪除項目
- 21. jQuery - 刪除'對應'項目
- 22. 刪除localStorage中的項目
- 23. 刪除ListView中的項目
- 24. 刪除選中的項目
- 25. 刪除ReactJS中的項目
- 26. 刪除RecyclerView中的項目
- 27. 刪除ViewPager中的項目
- 28. 刪除陣列中的對象項目
- 29. 如何從Web項目中刪除「App_data」?
- 30. Xcode 4:從項目中刪除文件?
行爲上的差異是由於Web應用程序項目使用基於MSBuild的項目系統來確定包含哪些文件(並在.csproj/.vbproj中列出),而Web站點項目只是查看文件系統。 – Jimmy 2012-02-06 20:17:27
您可以構建項目,然後您將獲得缺失文件的列表。根據此列表,您可以檢測丟失的文件並將其刪除。 – starikovs 2012-07-16 13:01:56