我在VS2010背后删除了一些被Web项目引用为Content的图片文件夹中的图像。 在解决方案导航器中,这些文件现在显示为黄色警告图标,表示找不到文件。 刷新文件夹没有效果。 有没有办法告诉VS2010自动同步文件夹? VS网站项目默认会这样做。
我在VS2010背后删除了一些被Web项目引用为Content的图片文件夹中的图像。 在解决方案导航器中,这些文件现在显示为黄色警告图标,表示找不到文件。 刷新文件夹没有效果。 有没有办法告诉VS2010自动同步文件夹? VS网站项目默认会这样做。
del
键(或右键选择Delete
)。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/
回答 Nov-2018,因为像我这样的人可能会遇到这个问题。
问题:
我已备份了项目中的一些文件夹。
由于文件是原始文件的副本,所以函数定义被引用。
现在当我尝试从函数调用打开函数定义时,会打开备份文件夹中的函数定义。
在删除备份文件夹后,它显示错误:xyz.php
文件未找到,请创建一个。
解决方案:
进入资源管理器中的文件夹,
点击刷新图标。
重新启动 Visual Studio Code。
在资源管理器中打开项目,找到扩展名为“.vcxproj”的文件,并从中删除您想要删除的文件,然后您就可以继续进行了。
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);
}
}
}