"Error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 2, position 1."
Jest to błąd przy kompilowaniu solucji Visual Studio. Jest to problem z plikiem sln, najprawdopodobniej jest on związany z mergowaniem z innego brancha. Nie może zależ guid projektu lub guid jest z duplikowany. Aby sprawdzić czy wszystko jest ok, wystarczy uruchomić skrypt sprawdzający identyfikatory projektów:
function Test-Sln
{
Param
(
[string] $slnPath
)
Write-Host "Testing sln in $slnPath"
if(! (Test-Path($slnPath)))
{
throw "No file for $slnPath"
}
else
{
$slnContent = gc $slnPath
$regex_id = '(\{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\})'
$regex_id_proj = '(\"{[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}\}")'
$matches_id = [regex]::Matches($slnContent,$regex_id)
$matches_id_proj = [regex]::Matches($slnContent,$regex_id_proj)
$dict_id = Count-List $matches_id
$dict_id_proj = Count-List $matches_id_proj
$returnValue = $true
$keyChecked = 0
$dict_id.Keys | foreach {
$key= $_
$count = $dict_id[$key]
$key_proj = '"' + $key + '"'
if( $dict_id_proj.Keys -contains $key_proj)
{
$count_proj = $dict_id_proj[$key_proj]
if(($count -ne $count_proj) -and ($count_proj -gt 1))
{
Write-Error "Wrong amount of reference for id $key. $count refers to $count_proj projects"
$returnValue=$false
}
else
{
Write-Host "Project with id $key is ok"
}
}
else
{
Write-Error "Problem on id $key. There are $count refers in sln"
$returnValue=$false
}
$keyChecked+=1
}
Write-host "Checked $keyChecked projects"
return $returnValue
}
}
Do tego potrzebujemy funkcję zliczającą ilość elementów w liście:
function Count-List ($List) #not explicitly list type
{
$dic = @{}
$List| Foreach {
$id = $_.ToString()
if($dic.ContainsKey($id))
{
$counter = $dic.Get_Item($id);
$counter +=1
$dic.Set_Item($id,$counter);
}
else
{
$dic.Add($id,1)
}
}
return $dic
}
Przykład wywołania jest poniżej:
if(!(Test-Sln "SuperSolution.sln"))
{
throw "Errors in sln file"
}
Brak komentarzy:
Prześlij komentarz