Ger*_*iss 61 visual-build-professional visual-studio-2010 visual-studio-2008 visual-studio
如何修复"缺少根元素".什么时候做Visual Studio(VS)Build?
知道我应该在我的解决方案中查看哪个文件?
实际上,当使用"Make VS 2008"命令时,我在"Visual Build Pro"中收到此错误消息.在构建其他解决方案(例如大约20个)时,此命令工作得很好,我不确定为什么我的错误.
任何帮助将非常感谢.:)
我正在使用VS 2008和Visual Build Pro 6.7.
Ell*_*iot 45
在我的情况下,崩溃后导致问题(它是空白的)是xxxxxxxxxxxx.vcxproj.user文件.我重命名了,问题就消失了.
Ode*_*ded 32
确保任何XML文件(或由visual studio解释为XML文件的任何文件)都具有正确的XML结构 - 即一个根元素(具有任何名称,我rootElement在我的示例中使用):
<?xml version="1.0"?>
<rootElement>
...
</rootElement>
Run Code Online (Sandbox Code Playgroud)
sto*_*eur 32
当BOM发生时,你也会得到"缺少根元素":).BOM =字节顺序标记.这是一个额外的字符,当使用错误的编码保存时,它会被添加到文件的开头.
在处理XML文件时,有时在Visual Studio中会发生这种情况.您可以编写某些内容以将其从所有文件中删除,或者如果您知道它是哪个文件,则可以强制Visual Studio使用特定编码(utf-8或ascii IIRC)保存它.
如果你在VS以外的编辑器中打开文件(尝试记事本++),你会在<?之前看到两个有趣的字符.xml声明.
要在VS中修复此问题,请在VS中打开文件,然后根据VS的版本
Mal*_*lil 14
在我的情况下.我正在丢失指向NuGet.Config文件的元素错误.那时它看起来像是这样的事情
<?xml version="1.0" encoding="utf-8"?>
<settings>
<repositoryPath>Packages</repositoryPath>
</settings>
Run Code Online (Sandbox Code Playgroud)
然后我只添加configuration了实际包装整个xml的标签.现在为我工作正常
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<settings>
<repositoryPath>Packages</repositoryPath>
</settings>
</configuration>
Run Code Online (Sandbox Code Playgroud)
在我的情况下,当我打开.csproj文件时,它是空的,所以我转到我在 git 中的上一次提交并复制该文件的内容并将其粘贴到我当前的.csproj文件中。之后我删除了.csproj.user文件,重新加载了我的项目,一切又开始工作了。
小智 6
此错误是由损坏的proj文件引起的。
Visual Studio始终在特定文件夹中有备份项目文件。
请浏览至:
C:\Users\<Your user>\Documents\Visual Studio <Vs version>\Backup Files\<your project>
Run Code Online (Sandbox Code Playgroud)
您应该看到2个这样的文件:
Original-May-18-2018-1209PM.<your project>.csproj
Recovered-May-18-2018-1209PM.<your project>.csproj
Run Code Online (Sandbox Code Playgroud)
您只需要复制文件:
Original-May-18-2018-1209PM.<your project>.csproj
Run Code Online (Sandbox Code Playgroud)
并重命名为
<your project>.csproj
Run Code Online (Sandbox Code Playgroud)
并在根项目文件夹中覆盖。
问题解决了!
您还可以搜索该文件。使用 PowerShell 导航到您的项目目录并运行 Get-FileMissingRoot:
function Get-FileMissingRoot {
dir -recurse |
where {
($_ -is [IO.FileInfo]) -and
(@(".xml", ".config") -contains $_.extension)
} |
foreach {
$xml = New-Object Xml.XmlDocument;
$filename = $_.FullName
try {
$xml.Load($filename)
}
catch {
write ("File: " + $filename)
write ($_.Exception.Message)
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
我在运行 VS 2017 时遇到了这个问题,在构建时我收到了“缺少根元素”的错误。为我解决的是Tools > Nuget Package Manager > Package Manager Settings > General > Clear all Nuget Caches。这样做之后,我再次运行构建并修复了它。