Access EnvDTE from msbuild code when building in Visual Studio - msbuild

When I do a build from Visual Studio, on post-build I execute a PowerShell script from MSBuild using the PowerShell MSBuild Task (http://powershellmsbuild.codeplex.com/). In this PowerShell code I would like to add/modify items to my project using Visual Studio automation (through the EnvDTE object).
The exact case is:
For each X.asmx file in my project I need to add Xwsdl.aspx and Xdisco.aspx file that don't need compilation. I only want to do this if these files are not generated yet, or if the asmx file is newer than the current Xwsdl.aspx and Xdisco.aspx files. In case you wonder why I need these additional files: it's a SharePoint thing.
Addition:
Just added the following PowerShell code in the executed script:
$process = [System.Diagnostics.Process]::GetCurrentProcess()
Write-Host "Process name: $($a.ProcessName)"
Which returns:
Process name: devenv
Which means that msbuild is executed in the context of the Visual Studio process.

Related

msbuild ignores ValidateCasingOnIdentifiers generating sql with SSDT sqlproj

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

MSBuild Not Working TeamCity But Works From CommandLine

I'm at a total loss. We have TeamCity installed (TeamCity Professional 2017.2.3 (build 51047)). We run the MSBuild step with:
MSBuildVersion: Microsoft Build Tools 2017
MSBuild Tools Version:
15.0
and Command Parameters:
/t:Clean /p:DeployOnBuild=true /t:build /t:publish /p:PublishProfile=Properties\PublishProfiles\Deploy.pubxml /p:PublishDirectory=Deployment /p:Configuration=Release /p:VisualStudioVersion=15.0
When we run the build t shows:
_DeploymentUnpublishable [11:16:53][_DeploymentUnpublishable] Skipping unpublishable project.
TeamCity outputs at the start:
Starting:
C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MsBuildBootstrap.exe
/workdir:C:\TeamCity\buildAgent\work\c36dd5b119aec7b
"/msbuildPath:C:\Program Files (x86)\Microsoft Visual
Studio\2017\BuildTools\MSBuild\15.0\bin\MSBuild.exe"
If I navigate to the msbuildPath in the CommandLine and run the same command it builds and publishes without issue.
Any help would be greatly appreciated.
MSBuild Step In TeamCity:
I had this issue and resolved it by setting a Parameter towards the publishing profile.
This is what i had:
- *.csproj would build and publish in visual studio locally.
- TeamCity builds fine but when asked to Publish sends me the not helpful _deploymentunpublishable
I tried all the commands in the msbuild line but only the following setup works:
pre-step: Create a Publishing profile (*.pubxml) which outputs to a folder within your build. This should be saved in your /Properties folder of the build.
inside your configuration page, go to Parameters.
Add a new Parameter for "System". Call it PublishProfile (system.PublishProfile). Give it a vaule which is the name of your publish profile file or *.pubxml
enter image description here
create a new step (or amend existing publish step), runner type "MSBuild" and in the Targets box type WebPublish
enter image description here
You dont need any command line parameters as your pubxml will handle all this.
Thats it, give it a try and your code should now publish to the folder you set in the publishing profile.

USQL msbuild - composite build output

I'm following the instructions on this link https://blogs.msdn.microsoft.com/azuredatalake/2017/10/24/continuous-integration-made-easy-with-msbuild-support-for-u-sql-preview/
It states that
After running MSBuild from command line or as a VSTS task, all scripts in the U-SQL project are built and output to a single file at "Build output path/script name/script name.usql". You can copy this composite U-SQL script to the release folder for further deployment.
Within my Visual Studio project (.usqlproj) I have multiple .usql scripts
CreateDatabase.usql
CreateTable.usql
CreateTvf.usql
when I do clean and msbuild and then check bin\debug folder, all I get is just CreateDatabase.usql and within that there is only CREATE DATBASE statement. As per the blog I would have thought all the 3 usql scripts would have merged into 1 composite usql script. The msbuild command I executed from command prompt on my machine
msbuild TheProject\TheProject.usqlproj /t:Clean /t:Rebuild /property:USQLSDKPath=C:\TheProject\src\packages\Microsoft.Azure.DataLake.USQL.SDK.1.3.1019-preview\build\runtime,USQLTargetType=Merge
I'm using Visual Studio 2017 15.4.3 and Azure Data Lake tools 2.3.0000.1
What am I doing wrong?
Due to some legacy reasons, to make sure all files in the usqlproj are built, the condition are defined in
USqlSDKBuild.targets as below
<ItemGroup>
<FileToBuild Condition="'$(JustOneFile)' == '' and
'$(Build_all_files_in_this_project)' != 'true'" Include="$(ActiveFile)" />
<FileToBuild Condition="'$(JustOneFile)' != '' " Include="$(JustOneFile)" />
<FileToBuild Condition="'$(Build_all_files_in_this_project)' == 'true'"
Include="Build_all_files_in_this_project" />
</ItemGroup>
For current preview release, please add "/property:Build_all_files_in_this_project=true,JustOneFile=''" to the command line to make sure all scripts are built. We will update this in later releases with a easier and simpler condition.
The command msbuild TheProject\TheProject.usqlproj /t:Clean /t:Rebuild /property:USQLSDKPath=C:\TheProject\src\packages\Microsoft.Azure.DataLake.USQL.SDK.1.3.1019-preview\build\runtime,USQLTargetType=Merge actually build the script you selected.
If you are selecting CreateDatabase.usql in VS, it will build the script CreateDatabase.usql in command line.
As below example, since it's selecting test.usql, when execute msbuild command, it will only build test.usql. As the way clicking Build button for the USQL project.
If you want to build all the scripts under the USQL project, you should select Build All Scripts button in VS.

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

Visual Studio Team Services Continuous Integration: NuGet Restore Task Failed

I am using Continuous Integration feature in Team Services (was Visual Studio Online). My build definition targets a specific project in a solution (not the whole solution), which is ClientUI MVC website.
The solution contains three projects:
ClientUI
AdminUI
Client Services
The Build Definition for ClientUI Project:
Repository:
Nuget Installer Step:
I have tried different params but not working.
Visual Studio Build
Before trying to target the a single project, my build definition was targeting the whole solution with the following parameters:
NuGet Installer -> Path to Solution: **\*.sln
Visual Studio Build -> Solution: **\*.sln ; MSBuild Arguments: /p:outdir=$(build.artifactstagingdirectory)
It was working. However now, it generates this error in the Nugget Restore Task:
2016-04-22T21:07:00.6716725Z Set workingFolder to default: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.98.1\tasks\NuGetInstaller\0.1.25
2016-04-22T21:07:00.8163908Z Executing the powershell script: C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.98.1\tasks\NuGetInstaller\0.1.25\NuGetInstaller.ps1
2016-04-22T21:07:01.5283529Z ##[error]Cannot find path 'C:\a\1\s\packages.config' because it does not exist.
2016-04-22T21:07:01.5439897Z C:\LR\MMS\Services\Mms\TaskAgentProvisioner\Tools\agents\1.98.1\agent\worker\tools\NuGet.exe restore "C:\a\1\s\packages.config" -NonInteractive
2016-04-22T21:07:03.0441507Z MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
2016-04-22T21:07:03.0597010Z ##[error]Cannot determine the packages folder to restore NuGet packages. Please specify either -PackagesDirectory or -SolutionDirectory.
2016-04-22T21:07:03.0909881Z ##[error]Unexpected exit code 1 returned from tool NuGet.exe
Try setting "Installation type" to "Install" for "Nuget Installer" task since you are using "packages.config" to install the packages.
For anyone curious, the source of the error about "Please specify either -PackagesDirectory or -SolutionDirectory" is that the build process is trying to issue a command similar to this:
C:\hostedtoolcache\windows\NuGet\4.4.1\x64\nuget.exe restore D:\a\1\s\MyProject\packages.config -PackagesDirectory packages -Verbosity Detailed -NonInteractive
The below screenshots should help if you want to build a project (rather than the solution) and your nuget "packages" folder is at the solution-level.
Additionally, you may need to specify this as the "MSBuild Argument" in the build task of your project: /p:SolutionDir="/"
I had the same thing sorted it out by changing the mapping - go to Repository tab, I had my mapping to another directory which means the nuget installer could not execute.