Wednesday, August 26, 2015

Visual Studio External Tools Limitation

If you use the External Tools feature available in Visual Studio for running your external tools such as MSBuild, you might encounter a severe limitation in the IDE which may prevent you from using Visual Studio as your de facto MSBuild Tool.

When you add an External Tool to Visual Studio, you have the option to specify arguments as well as "Prompt for Arguments"






However, if you look at the length of the arguments that you can specify, you will quickly discover that there is a HARD limit to how many characters that you can add to the Arguments field for your External Tools!

Therefore, if you attempt to create an argument consisting of several hundred characters, you will notice that the Visual Studio IDE will truncate out all of the additional characters from your arguments, thus resulting in unexpected behavior if you do not expect the IDE to truncate your arguments!

So what is the solution to this problem??

Well, you can use an alternative IDE/editor such as EditPlus as described in this article: http://samirvaidya.blogspot.com/2013/10/how-to-run-msbuild-from-editplus-3x.html

Otherwise, you can simply use PowerShell!!


Below is a sample PowerShell script for running MSBuild with Targets and Properties:

$MSBuild = "C:\Program Files (x86)\MSBuild\14.0\Bin\amd64\MSBuild.exe"
$MSBuildProjFile = "C:\MyBuild.proj"
$MSBuildTarget = "PublishProject"
$WebProjectPath = "C:\MyWebProject.csproj"
$SolutionPath = "C:\MyBuildSolution.sln"
$PublishFolder = "C:\Published"
 
 
Clear-Host
 
#Run the MSBuild Command
Write-Host $MSBuild $MSBuildProjFile /t:$MSBuildTarget /p:"SolutionPath=$SolutionPath;WebProjectPath=$WebProjectPath;PublishFolder=$PublishFolder"
& $MSBuild $MSBuildProjFile /t:$MSBuildTarget /p:"SolutionPath=$SolutionPath;WebProjectPath=$WebProjectPath;PublishFolder=$PublishFolder"

No comments:

Post a Comment