msbuild ignores ValidateCasingOnIdentifiers generating sql with SSDT sqlproj - msbuild

I set my sqlproj to not validate casing on identifiers, but when I generate a sql script with msbuild, it seems to ignore that and shows warnings like warning SQL71558: The object reference [dbo].[table].[deleted] differs only by case from the object definition [dbo].[table].[Deleted]..
Note when building from within visual studio, the warnings are not shown, as expected.
Here's what I'm running at cmdline:
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe" /p:Configuration=Release /p:Platform=AnyCpu /p:TargetDatabaseName=dbName /p:TargetConnectionString="Data Source=.\SQLExpress;Initial Catalog=dbName;Integrated Security=True" /p:DeployScriptFileName=publish.sql /p:UpdateDatabase=False /p:CommentOutSetVarDeclarations=True /t:Rebuild,Deploy "c:\dev\project\Sql.sqlproj"
I also tried to add /p:ValidateCasingOnIdentifiers=False to the msbuild command, but that didn't work either.
I confirmed that my sqlproj has the line <ValidateCasingOnIdentifiers>False</ValidateCasingOnIdentifiers> that was put there when I clicked the checkbox in project settings in the project properties GUI in visual studio.

I got it to work by adding a line in my sqlproj file, directly under where I had <ValidateCasingOnIdentifiers>False</ValidateCasingOnIdentifiers>:
<SuppressTSqlWarnings>71558</SuppressTSqlWarnings>
This article lead me to find that: https://developercommunity.visualstudio.com/content/problem/19394/unable-to-suppress-build-warnings-for-sql-db-proje.html

Related

MSBuild looking in wrong place for Microsoft.VisualBasic.Core.targets

I am setting up a new TeamCity build agent. Several build configurations that run perfectly well on the existing agent are failing on the new agent, with errors like this (whitespace added for clarity):
[22:14:32][someproject.vbproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin\Microsoft.VisualBasic.CurrentVersion.targets(322, 5):
error MSB4019: The imported project
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\bin\Roslyn\Microsoft.VisualBasic.Core.targets"
was not found.
Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
Note the path on line three after "The imported project". The error is correct; the folder does exist but the file does not exist there. However the Microsoft.VisualBasic.Core.targets file does exist at a slightly different path
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\Roslyn\Microsoft.VisualBasic.Core.targets
Is there an easy fix for this, perhaps a registry entry telling MSBuild where to look?
Cause
On your machine, there are two copies of VS 2017 installed, Professional edition and the raw Build Tools.
You didn't install VB bits for Professional, while did that for Build Tools.
TeamCity prefers MSBuild from Professional edition.
Combine all above, the issue happened.
Fix
You should either force TeamCity to use MSBuild from Build Tools, or add VB to your VS Pro installation.
Reference
https://blog.lextudio.com/the-rough-history-of-msbuild-cc72a217fa98

Visual Studio automatically renames external tool path

I am trying to set some external tools paths in Visual Studio 2017 and for some reason, certain entries get automatically renamed. Under
Tools > Options > Projects and Solutions > Web Package Management > External Web Tools
I am trying to enter $(VSINSTALLDIR)\Web\External but after clicking [OK] on the Options dialog, this then gets renamed to $(VSInstalledExternalTools).
I made a small MSBuild script to test the values of each of these variables. This included the following message statements:
<Message Text="$(VSInstallDIR)\Web\External"></Message>
<Message Text="$(VSInstalledExternalTools)"></Message>
The first one outputs "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Web\External" whereas the second outputs an empty string. This is breaking my build process, but I cannot figure out how to resolve.
...Hard to say:
But please use $(VSINSTALLDIR)Web\External instead of $(VSINSTALLDIR)\Web\External.
The latter one equals: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\\Web\External
Line6: Result of $(VSINSTALLDIR)\Web\External using \\
Line7: Result of $(VSINSTALLDIR)Web\External.
I think the \\ causes this issue. Hope it helps.

TFS 2013 using VS2015 MSBuild with TfvcTemplate.12.xaml template

After adding MSBuild arguments:
/tv:14.0 /p:VisualStudioVersion=14
I get the following error message:
C:\Builds\10\IW_*****\Dev\src\Sites\******\Properties\CompileLicxFiles_Patched.targets (98): The "LC" task was not given a value for the required parameter "TargetFrameworkVersion".
I'm trying to build using VS2015 (TFS2013 server)
Found this: https://connect.microsoft.com/VisualStudio/feedback/details/1406942/new-required-lc-task-parameter-targetframeworkversion
However, I've checked and all projects in the solution have 4.5.2 version assigned.
Log (it seems it's still using VS2013):
Added package 'NEST.1.9.1' to folder ...
Added package 'FluentAssertions.4.17.0'....
...
C:\Program Files (x86)\MSBuild\12.0\bin\amd64\MSBuild.exe /nologo /noconsolelogger "C:\Builds\10\IW_****\Dev\src\Solution123.All.sln" /nr:False /fl
To use VS 2015, the argument should be /p:VisualStudioVersion=14.0.
First thing first.
I was using VS2015 to edit TfvcTemplate.12.xaml build template which cased issues. For some reason, when using VS2015 - it was modifying the xaml document incorrectly. To make any type of changes to TfvcTemplate.12.xaml template you have to use VS2013!
TfvcTemplate.12.xaml does not contain "ToolPath" variable. To make this work I simply added "14.0" (quotes necessary) under "ToolVersion"
TFS2013 will use VS2015 MSBuild to run the build. No need for MSBuild command line switches. Works without them.
Output log:
Run MSBuild00:13:39 C:\Program Files\Microsoft Team Foundation Server
12.0\Tools\nuget.exe restore "C:\Builds\9************\packageRestore.proj" -NonInteractive MSBuild
auto-detection: using msbuild version '14.0' from 'C:\Program Files
(x86)\MSBuild\14.0\bin'.
You could also just modify your build definition with Visual Studio. On the process tab of the build definition that uses TfvcTemplate.12.xaml expand 2.5 section to see the MSBuild arguments. Add the below arguments to the build definition and save it. I assume your problem was you had /p:VisualStudioVersion=14 instead of /p:VisualStudioVersion=14.0.
/p:VisualStudioVersion=14.0 /tv:14.0

TeamCity FxCop Selecting MinimumRecommendedRules.ruleset has no effect

I have added a Build Step in TeamCity 8.0.6 (build 27767) to execute FxCop against a specific c# project assembly.
When running FxCop from within VS 2013 with the MinimumRecommendedRules set I get no errors or warnings (I fixed them all).
Now I want to wire this up in TeamCity. To limit the rules I am specifying a command line property as follows:
/ruleSet:=MinimumRecommendedRules.ruleset /rulesetdirectory:'FxCop\Rule Sets'
(The rulesetdirectory parameter points to a location in my source tree which contains the full contents of the standard Rule Sets folder)
However this does not have the desired behaviour, the FULL rule set is run and I get an error as follows:
FxCop warning: Keyword=CA0063 Kind=Engine Type=Microsoft.FxCop.Sdk.FxCopException * Failed to load rule set file 'MinimumRecommendedRules.ruleset' or one of its dependent rule set files.
And this is the TeamCity generated command line:
[17:32:29]Starting: "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe" /forceoutput /ignoregeneratedcode /ruleSet:=MinimumRecommendedRules.ruleset "/rulesetdirectory:'FxCop\Rule Sets'" /f:dal\bin\release\MyDAL.dll /out:C:\TeamCity\buildAgent\temp\buildTmp\fxcop-output-1891867450083417003\fxcop-result.xml
Can anyone spot what is wrong?
I figured it out so hopefully this is helpful to someone else.
the /ruleSet: parameter needed to have the full (relative or absolute) path to the ruleset file as follows:
/ruleSet:"=%teamcity.build.workingDir%\FxCop\RuleSets\MinimumRecommendedRules.ruleset"
(Note: the double quotes are to handle the possibility that the teamcity.build.workingDir might contain spaces)
Secondly, the second command line parameter /rulesetdirectory: is no longer necessary. I suspect this second parameter does not actually work.
Please also note, my working command line parameter here points at my MinimumRecommendedRules.ruleset file in my source code. It could just as easily have been copied into the standard Rule Sets folder under "c:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\Rule Sets".
And finally, as my projects are all VS 2013 and TeamCity only recognises up as far as v10 I also set "Specifiy installation root" to "c:\Program Files (x86)\Microsoft Visual Studio 12.0\Team Tools\Static Analysis Tools\FxCop" explicitly to ensure that the latest version of FxCop was being used and would not choke on .Net 4.5 code. (Note: I have VS 2013 installed on the build server because of C++ project build requirements, I'm not happy about this but it turned out to be convenient for me in dealing with the FxCop set up. There are other ways to put the FxCop stuff on your build server without installing VS 2013)

Database msbuild publish not working from command line

I am trying to Publish a .sqlproj from command line with MSBuild with the command:
msbuild /t:Publish [MySqlProjPath] but i get the following error:
error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
What i find weird is that from Visual Studio 2012 i can Publish the same project successfully. Does Visual Studio set any magical msbuild property before publishing to get the .targets file from another directory?
You should pass the following argument to MSBuild:
/p:VisualStudioVersion=11.0 /t:Rebuild;Publish
This tells msbuild to use VS2012 targets.
Passing VisualStudioVersion is required hence VS2010 and Vs2012 can share the same project file: i.e. project file does not store target VS version inside itself