Not able to specify - MSbuild:OutDir as a variable - msbuild

I am trying to set up a command line build (currently using TFS build & moving to Jenkins based build). MsBuild's OutDir parameter does not seem take %MainPath% argument correctly.
set MainPath="C:\Users\jayapraa\Documents\Visual Studio 2017\Projects\"
set MSBuildPath="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\"
cd %MSBuildPath%
msbuild.exe "C:\Users\jayapraa\Documents\Visual Studio 2017\Projects\WindowsFormsApp1\WindowsFormsApp1.sln" /t:Build /p:OutDir=%MainPath%;Configuration=Release;Platform=x64;TargetFrameworkVersion=v4.7.1

set "baseName=C:\Output\Full Build\Full Build-%Year%%Month%%Day%-" - setting the
variable within quotes made it work..
MSBuild.exe "Mtell.Reservoir.sln" /t:Rebuild /p:OutDir="%baseName%%n%";

Related

How to specify environment variables in .csproj file

How can I, through the .csproj file, specify environment variables to apply during the build, such as when building with Rider?
Specifically, I want to set DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 so that I can build from within the IDE, without resorting to the command line (see below).
Adding <InvariantGlobalization>true</InvariantGlobalization> to the project file did not work, since that does not affect the underlying/imported build target, but executing export DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1 before dotnet build NAME.csproj worked.
Background: A recent distro upgrade on openSuse Tumbleweed bricked MonoGame project builds with the following error message when invoking mgcb (re-installing ICU with Zypper did not fix the issue):
Couldn't find a valid ICU package installed on the system. Set the configuration flag System.Globalization.Invariant to true if you want to run with no globalization support.
(...)
error MSB3073: The command "dotnet (...) exited with code 134
Edit: I have finally gotten a Target to run before the Nopipeline target using InitialTargets. The problem now is the Exec task runs in a discarded scope.
Depending on which task fails, you can hope that the target author added an option to set the environment variables.
E.g. for C# compilation, you could set:
<PropertyGroup>
<CscEnvironment>$(CscEnvironment);DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1</CscEnvironment>
</PropertyGroup>
If the tool is run by a custom target, you would need to author a replacement target that allows setting the environment variable.

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

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

MsBuild publish website without using publish profile

A publish profile to publish a Visual Studio Website can be used from both the Visual Studio 2013 publish dialog, and from the command line MsBuild as explained in this question Using msbuild to execute a File System Publish Profile
C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBuild.exe
./ProjectRoot/MyProject.csproj /p:DeployOnBuild=true /p:PublishProfile=FileSystemDebug
However, I want to get rid of the publish profile completely and do everything from the command line - because I do not want the publish path to be hard-coded in the PublishProfile xml file. How can I specify the same options directly in the command line arguments? I have tried using OutDir instead, but that results in a different behavior than the path specified in the PublishProfile (an extra _PublishedWebsites is appended to my path).
You can actually override the PublishProfile settings from the command line. You would want this parameter:
/p:publishUrl=pathToPublishHere
If it's local filesystem this should work just fine.
publish.bat
SET PROJECT="D:\Github\MyWebSite.csproj"
SET MSBUILD_PATH="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin"
SET PUBLISH_DIRECTORY="C:\MyWebsitePublished"
cd /d %MSBUILD_PATH%
MSBuild %PROJECT% /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:WebPublishMethod=FileSystem /p:DeleteExistingFiles=True /p:publishUrl=%PUBLISH_DIRECTORY%
needs a Visual Studio to be installed on server.

MSBUILDEMITSOLUTION not working with .NET 4?

In prior versions of MSBuild, you could set an environment variable named MSBUILDEMITSOLUTION to 1 to get an XML version of a solution (.sln) file that could be parsed. According to the MSBuild Team Blog, that's still in the version that ships with Visual Studio 2010, but it does not seem to be working.
Has anyone managed to get this working with MSBuild 4.0? If so, what is required?
(We use this to find and run convention-based unit tests with an NAnt script.)
Set MSBuildEmitSolution=1 and then build from the command line. You should then see a MySolution.sln.metaproj file near MySolution.sln.
Notes:
If you open a command prompt window, then set the env var via System Settings, you will have to open a new command prompt.
You'd think you could also use msbuild /p:MSBuildEmitSolution=1, but you can't.