Working with suppress warnings in Visual Studio Database Solutions

MS Database Projects have come a long way from their humble beginnings especially with GDR and now full integration into VS2010, but plenty of issues remain. One of the more persistent problems is tracking references. Sometimes we just have to repress those warnings (code 4151). (http://msdn.microsoft.com/en-us/library/aa980442(v=vs.80).aspx) :

setting Suppress Warnings 4151

 

that’s all fine and
good and gets us out of a bind short term, but if you really are going to use your DB project as intended, you should keep the number of objects that need this to a minimum. One problem is that once you set it, there is no visual way to identify a “suppressed” object. One way out of it is to parse the dbproj file. With Powershell, of course, it doesn’t get any simpler. Here is a script that I use. I’ve added comments for clarity:

 
#H4151.ps1

$root="."
#check if the output file exists, if so delete it
IF (Test-Path c:\temp\output.csv)
{Remove-Item c:\temp\output.csv}

# Create a file header
$output="DBProject,SQLObjects `r`n"

#get the files
$files=(dir $root -r | where {$_.extension -match "dbproj"}|Get-Item)
foreach ($file in $files)
{
#get the file naame
$ProjectName=$file.Name
$ProjectName

#get the second ItempGroup block
$fileString=Get-Content $file
$text_list=[regex]::Matches($fileString,"<ItemGroup>(.*?)</ItemGroup>") | Select-String "SuppressWarnings" | %{$_.line}

#let's add a root element to the list
$text_list="<root>"+$text_list+"</root>"

$xd=$text_list

#get all the object Names
$xd.SelectNodes("/root/ItemGroup/Build[SuppressWarnings=4151]") | %{
$objName=($_.Include).split("")[-1]
write-host $ProjectName,$objName;
$output=$output + $ProjectName + ","+ $objName+ "`r`n"
}
 
}

Out-File -filepath c:tempoutput.csv -InputObject $output -Append

 

Share this post

Share on facebook
Share on twitter
Share on linkedin
Share on pinterest
Share on print
Share on email

Leave a Reply

Your email address will not be published.

Are you #CuriousAboutData? This is a members’ only discussion forum for any CTO, Developer, DBA, Data Engineer/Scientist — or anyone who just wants to know more about using and managing data. Members enjoy open debate, ask/ answer questions, offer opinions, expertise, and support. If your curiosity has no limits, this group is for you!