Team city MSBuild Exclude Multiple Files - msbuild

I have the following for command line parameters. This is the team city build step. I need to exclude web.config and robots.txt.
/p:DeployOnBuild=True
/p:PublishProfile=OffCycleDevelopmentRemoteDeployment
/p:ProfileTransformWebConfigEnabled=False
/p:VisualStudioVersion=12.0
/p:ExcludeFilesFromDeployment=Web.config;robots.txt
My build is failing when i try to "Run" the project.
[15:34:30]Step 1/1: Visual Studio Build and Publish (Visual Studio (sln)) (1s)
[15:34:30][Step 1/1] Starting: C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MsBuildBootstrap.exe /workdir:C:\TeamCity\buildAgent\work\McoMobile-OffCycle "/msbuildPath:C:\Program Files (x86)\MSBuild\12.0\bin\MSBuild.exe"
[15:34:30][Step 1/1] in directory: C:\TeamCity\buildAgent\work\McoMobile-OffCycle
[15:34:31][Step 1/1] MSBuild command line parameters contain "/property:" or "/p:". It is recommended to define System Property on Build Parameters instead.
[15:34:31][Step 1/1] Process exited with code 1
[15:34:31][Step 1/1] MSBuild output
[15:34:31]Start MSBuild...
[15:34:31]'C:\Program Files (x86)\MSBuild\12.0\bin\MSBuild.exe' '"#C:\TeamCity\buildAgent\work\Mobile-OffCycle\Mobile.sln.teamcity.msbuild.tcargs" "C:\TeamCity\buildAgent\work\Mobile-OffCycle\Mobile.sln.teamcity"'
[15:34:31]working dir = 'C:\TeamCity\buildAgent\work\Mobile-OffCycle'
[15:34:31]Microsoft (R) Build Engine version 12.0.30723.0
[15:34:31][Microsoft .NET Framework, version 4.0.30319.18408]
[15:34:31]Copyright (C) Microsoft Corporation. All rights reserved.
[15:34:31]
[15:34:31]MSBUILD : error MSB1006: Property is not valid.
[15:34:31]Switch: robots.txt
[15:34:31]
[15:34:31]For switch syntax, type "MSBuild /help"
[15:34:31][Step 1/1] Step Visual Studio Build and Publish (Visual Studio (sln)) failed
If i keep only one file then no error occurs.
/p:ExcludeFilesFromDeployment=Web.config
How can i specify multiple files here?
I tried following but this is posts my files to the web site.
/p:ExcludeFilesFromDeployment=Web.config
/p:ExcludeFilesFromDeployment=robots.txt

You need to quote property value, e.g. /p:ExcludeFilesFromDeployment="Web.config;robots.txt"
Also see this question if you need to convert your property value into item list
I'm not sure where have you found property ExcludeFilesFromDeployment, but I assume it's working one and there is a MSBuild target to handle expected behaviour.

Related

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.

Duplicate error messages in .NET Core - error CS0116

Steps to reproduce
dotnet new console
(introduce a bug in Program.cs)
dotnet restore
dotnet build
The typical output would be:
Microsoft (R) Build Engine version 15.1.548.43366 Copyright (C) Microsoft Corporation. All rights reserved.
Program.cs(5,5): error CS0116: A namespace cannot directly contain members such as fields or methods [/Users/xxx/Documents/myproj/myproj.csproj]
Build FAILED.
Program.cs(5,5): error CS0116: A namespace cannot directly contain members such as fields or methods [/Users/xxx/Documents/myproj/myproj.csproj]
0 Warning(s)
1 Error(s)
Time Elapsed 00:00:01.77
You can see the error CS0116 is reported twice.
Is there a way to avoid the duplication in the reporting of errors?
The second error is part of the console logger's summary. This can be disabled by passing in /clp:NoSummary to msbuild. However, there is currently a bug in the CLI when it is the first MSBuild argument to dotnet build. Add any other MSBuild command before it to make it work. Since you want to reduce the verbosity, let's just use /nologo for the workaround:
dotnet build -c Release /nologo /clp:NoSummary
However, it works great if you use MSBuild directly:
dotnet msbuild /clp:NoSummary /p:Configuration=Release
In the upcoming 2.0.0 release, the CLI always overrides the summary parameter for dotnet build, so you'll have to use dotnet msbuild instead (I opened an issue on GitHub on that).
You can make your own MSBuild logger, instead of using the default console logger. There are really good instructions in Build loggers.
Essentially, you could make your own logger that captured all the data, and then emitted a simple summary at the end.
dotnet build /noconsolelogger /logger:YourCustomLogger.dll

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 unpublishable project

I have a .vbproj which is a VB.NET web application project. I can build the solution that contains this project and then right click on the project and publish locally. No issues from with VS 2013 professional update 3.
I am trying to build this solution and then publish the project outside of VS using the msbuild plugin from within Jenkins CI.
The project does not get published as it says it is skipping unpublishable project.
The command and it output is as follows:
Executing the command
cmd.exe /C C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
/t:Publish /p:VisualStudioVersion=12.0 /p:OutDir=C:/temp/eric
StarWebPortal/StarWebPortal/StarWebPortal.vbproj && exit
%%ERRORLEVEL%% from C:\Tools\Jenkins\jobs\STAR-dev_POC\workspace
[workspace] $ cmd.exe /C
C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe /t:Publish
/p:VisualStudioVersion=12.0 /p:OutDir=C:/temp/eric
StarWebPortal/StarWebPortal/StarWebPortal.vbproj && exit
%%ERRORLEVEL%% Microsoft (R) Build Engine version 4.0.30319.18408
[Microsoft .NET Framework, version 4.0.30319.18444] Copyright (C)
Microsoft Corporation. All rights reserved.
Build started 8/22/2014 11:46:51 AM. The target "MvcBuildViews" listed
in a BeforeTargets attribute at "C:\Program Files
(x86)\MSBuild\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.targets
(840,131)" does not exist in the project, and will be ignored. Project
"C:\Tools\Jenkins\jobs\STAR-dev_POC\workspace\StarWebPortal\StarWebPortal\StarWebPortal.vbproj"
on node 1 (Publish target(s)).
_DeploymentUnpublishable: Skipping unpublishable project. Done Building Project
"C:\Tools\Jenkins\jobs\STAR-dev_POC\workspace\StarWebPortal\StarWebPortal\StarWebPortal.vbproj"
(Publish target(s)).
Any idea why it works from within VS and not from the msbuild command line?
You have to configure Jenkins to pass two additional arguments to MsBuild.exe which are /p:DeployOnBuild=true and /p:PublishProfile=your_publish_profile.pubxml.
The command should be like msbuild your_vb_project.vbproj /p:DeployOnBuild=true /p:PublishProfile=publish_profile.pubxml You don't need to specified path to publish_profile.pubxml as long as it's under the same directory with your vbproj.
As of Visual Studio 2013, MSBuild is now a separate component from the .NET Framework and is included in the install with VS. It is also available as a separate download for build servers. It looks like you are using the "old" v4.0 MSBuild path. You need to use the new MSBuild path which is something like C:\Program Files(x86)\MSBuild\12.0\bin. You need to configure the Jenkins MSBuild plugin to use this path.

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