How to make MSBuild CoreClean before copy step? - msbuild

I have a Class Library Project which contains t4 templates that execute on build. The output .sql files are set to Content of the .csproj and should be copied on build to the output folder.
I have the following configuration setup on my TeamCity Build Box using MSBuild:
Command line parameters:
/p:OutDir=C:\output\DBMigration
/p:Configuration=Release
/p:DebugSymbols=false
/p:DebugType=None
/p:DeleteExistingFiles=true
/t:rebuild
/verbosity:n
The output of this is that the files are copied to the outputdir but are deleted in the CoreClean step of the rebuild.
To get around this I can run a Build instead of a rebuild, (ie. /t:build).
This will skip the CoreClean step, but why is the CoreClean called on the output dir after the Copy process has taken place? Should the Delete action not be before the Copy?
And why do I only need to do this step for ClassLibrary type projects, web/windows applications do not seem to have this problem with the rebuild.
Also it appears from the build log that the output directory is never cleaned by /p:DeleteExistingFiles=true.
I could do a hack and force a powershell script to run to clean the directory before attempting to build, but there must be a supported MSbuild parameter to do this in the absence of the rebuild preforming correctly?

Related

MSBuild skips some tasks when DeployOnBuild and PublishProfile parameters are present

When I build a web project from command-line using msbuild and no special parameters, it seems to build just fine, including calling an nswag task to build TS files.
When I build the same web project with the /p:DeployOnBuild=true parameter and the /p:PublishProfile parameter set, nswag is not called at all, and the build fails because none of the TS files were built.
Isn't using the DeployOnBuild parameter additive? Shouldn't any build tasks specified in the csproj file still get executed?
Using the Structured Log Viewer for MSBuild I was able to determine why MSBuild seemed to be skipping the NSwag task specified in my csproj file when DeployOnBuild=true.
Build order matters!
In our project we build a client TS file at build time and then at the end run yarn tsc to build out all of the JS files.
Wnen we add DeployOnBuild=true, early in the build process, it attempts to copy the JS files to the package folder. But because client TS file hadn't been built yet and the JS file created from it, the build was failing and never even getting to the NSwag command.

Why is building two targets with msbuild different from building each target separately?

I have a project that imports a certain targets file from a Nuget package. Even though I use PackageReferences I am forced to import this file manually.
(See my other question for details - How are we supposed to execute package build targets in the new world where nuget packages are consumed through msbuild PackageReference?)
This targets file injects chromedriver.exe into the Content item group with CopyToOutputDirectory = PreserveNewest.
I observe a situation where chromedriver.exe is not copied to the bin folder when running msbuild /t:"Restore;Build", but it is copied when running the two targets separately - msbuild /t:Restore; msbuild /t:Build.
Can anyone explain how this happens?
(I killed a good portion of the day learning the difference on my skin, want to know how come?)
Restore changes the imported project files in the obj\ directory.
For this to take effect, the project file needs to be re-evaluated entirely, which does not happen when you run the Restore and Build targets in the same invocation.
Use the -restore command line switch for MSBuild to run a Restore before the other specified targets in the same command line call. MSBuild will run the Restore, empty its XML caches and re-evaluate the project again when running the requested build.

Is it possible to run the MSBUILD.SONARQUBE.RUNNER on a CSProj file as opposed to a solution?

I have a TFS xaml Build template that runs the msbuild.sonarqube.runner start (and end) before and (after the) msbuild task in the xaml.
It all works well enough with a .sln file. As the file under build.
However, when I attempt to use this on a build that runs msbuild on a .csproj file the end process reports that it cannot find the postprocess exe.
"Execution failed. The specified executable does not exist: .sonarqube\bin\MSBuild.SonarQube.Internal.PostProcess.exe"
there no error indication given by the Start command.
is there something special I need to do to get this to work, or is this a limitation of the MSBuild runner?
Please help.
My whole team is keen to use the tool, but as it is only a fraction of the existing builds are being analyzed
thanks
Jeff Gedney
The begin and end commands of the SonarQube Scanner for MSBuild, as well as all msbuild commands MUST be launched from the same current working directory. Indeed, they will all need access to the .sonarqube folder that is created by the begin command.
Other than that, you can launch MSBuild on a *.csproj file instead of a *.sln if you prefer - that is supported by the SonarQube Scanner for MSBuild.
I've created the following ticket to improve the error message in case end is launched from the wrong folder: https://jira.sonarsource.com/browse/SONARMSBRU-160
Make sure you put yourself in the root folder of the project you want to analyze, then run the following commands:
a.MSBuild.SonarQube.Runner.exe begin /k:"sonarqube_project_key" /n:"sonarqube_project_name" /v:"sonarqube_project_version"
b.Build the project, for example: msbuild /t:Rebuild
c.MSBuild.SonarQube.Runner.exe end
Check:http://docs.sonarqube.org/display/PLUG/C%23+Plugin

How do I copy the Release folder contents to a secondary location?

I am brand new to using TeamCity.
I have my .NET C# application building via a MSBuild "build step" in TeamCity. Once it is built, I would like TeamCity to copy the entire contents of the "Release" folder to a secondary location where we keep current and recent builds.
I cannot build to this location directly because there are other files which my application requires (databases, XML config files, etc..) that reside permanently in the Debug and Release folders. I know this is horrible and I would need a soapbox to complain about the decisions my predecessor made, but for not I am forced to keep that portion as-is.
You can add a command line build step with a simple xcopy command.
It will be executed only when every previous build step succeeds.

Generating an MSBUILD project file from a visual studio solution file and project files

I know that I can pass MSBuild a VS solution file (.sln) and it will build the solution but somewhere in the back of my mind, I remember using a MSBuild command line switch that would take a solution file (and it's referenced project files) and generate a single MSBuild project file from them. However, I now can't find this switch!
Was this all a dream?
I see the /preprocess switch (short form /pp) but I don't think that this was it as this will include all of the imported files (including Microsoft.*.targets) and besides I can't seem to get this switch to work. I when I try the following command line, MSbuild generates the *.out file but its empty!
msbuild /target:rebuild /generate MSBuildCopyTargets.sln
The easiest way to do this is to run MSBuild from the command line, with an environment variable set:
Set MSBuildEmitSolution=1
The output will be in the format SolutionName.metaproj