Perform Slowcheetah transformation only - msbuild

Hi I have a bunch of csproj visual studio projects.
These includedes alot of slowcheetah transformation files and alot of normal c# code files.
In order to optimize my build process, I would like to build these projects with "some flag" to msbuild, that will only transform the slowcheetah config files - and not build the dll and perform other build operations.
Anyone knows how to msbuild only the clowcheetah transformations?

Anyone knows how to msbuild only the clowcheetah transformations?
You can use the MSBuild task TransformXml to transform config files:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
<Target Name="AfterBuild">
<TransformXml Source="Config\App.config"
Transform="Config\App.$(Configuration).config"
Destination="$(OutputPath)\$(AssemblyName).$(OutputType).config" />
</Target>
With this task, MSBuild will transform the config based on the configuration. But since you are have a lot of config files for a bunch of csproj visual studio projects, so transform multiple config files for multiple projects should be your real issue.
To resolve this issue, you can create one target to list all the config files that need to be transformed, then another for the actual transforms. For some more detailes, please refer to the Danny`s question and answer:
Transforming multiple config files for multiple projects via MsBuildProj file
Hope this helps.

Related

Is it possible to extract the value of element in csproj file with dotnet CLI?

csproj file contains project properties which I'd like to use in CI/CD pipeline.
Is it possible to extract those values with dotnet cli (or some other standard tool) without parsing xml via some standalone script?
For example having the project:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.0.0</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
</<Project>
I need to resolve the value of <Version>.
It's also wroth noting that project may contain conditional elements, and ideally it would be nice to resolve properties in the context of predefined variables.
MSBuild is very extensible. You could use a target to write the version number to a file:
<Target Name="WriteVersion" AfterTargets="Build">
<WriteLinesToFile Lines="$(Version)"
File="$(IntermediateOutputPath)version.txt" />
</Target>
That would write a version.txt file to a folder such as obj/Debug/net5.0 (depending on the Configuration and TargetFramework).
Also be sure to check out https://msbuildlog.com/ for how to investigate / debug builds.

Config Transform in Azure DevOps

I would like to use a visual studio proj file to transform xml files. I am following this article. http://sedodream.com/2010/04/26/ConfigTransformationsOutsideOfWebAppBuilds.aspx . This works for me locally, however when deploying the application on Azure DevOps it fails. It cannot find Microsoft.Web.Publishing.Tasks.dll. How do I set up a build task that will only transform the config files.
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="TransformXml"
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v15.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
<Target Name="Build">
<TransformXml Source="Web.config"
Transform="Web.Release.config"
Destination="Web.Production.config" />
</Target>
</Project>
Turned out to be an easy fix. It was an old build so that the hosted agent. Just had to change it to the Hosted VS2017 agent.
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.Tasks.dll"/>
I think that's why the issue happens. For a vs2017 agent, you need to change the v10.0 to v15.0, so that the msbuild tool can find the assembly.
Also, as for vs2017, make sure you set the correct msbuild tool path in VSTS like this issue.

Directory.Build.Props and Msbuild /nr parameter

I have a quite huge solution and I need to add the /nr:false parameter to each build.I've found googling that starting from msbuild 3.5 it's possible to write a Directory.Build.Props and all the msbuild will realay to this one.
I've tried with this XMLbut doesn't seem to work
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBUILDDISABLENODEREUSE>1</MSBUILDDISABLENODEREUSE>
</PropertyGroup>
</Project>
What am I doing wrong?
Node reuse is a flag on msbuild itself, not in the projects. While environment variables are also treated as global properties in projects, some - like MSBUILDDISABLENODEREUSE - are interpreted by msbuild itself, before even processing projects. So setting a property with the same name inside a project file will have no effect.
In MSBuild 15.6 (in preview at the time of writing), it will support a similar concept with files named Directory.Build.rsp which can contain additional command line switches, so you can create a file with that name and /nr:false as content.

How to get jspm/webpack/browserify/requirejs bundling working with msdeploy?

I currently use jspm but the same issue applies with any other build-time bundling tool. I can't figure out how to get these to play well with msdeploy.
Here's the issue:
I run jspm to produce one or more bundle files (one for each "chain" that I want).
My application uses System.import (or require or just a script tag) to start these loading.
If I were to deploy everything to a directory and xcopy from there to the deployment server everything is copacetic. However, our devops team prefers to deploy using msdeploy. For this I'm supposed to point it at a csproj. If I do this then how does msdeploy know to deploy the generated bundles?
You have to create an MSBuild project to accomplish this - one which hooks into the MSDeploy pipeline. I've provided a sample (one I'm currently using for a project) below; I'm likely going to release this as a Nuget package (along with some other MSBuild scripts that were written to take advantage of npm, jspm, and gulp).
The props file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
FrontendDeploymentFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
</Project>
The targets file:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="FrontendDeploymentFiles">
<ItemGroup>
<_CustomFiles Include="dist\**\*" />
<_CustomFiles Include="jspm_packages\**\*" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>%(RelativeDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
</Project>
This isn't exactly a drop-in for you as you're bundling your files, but the takeaway here is that you can define a glob pattern for your copy methods. Replace jspm_packages with whatever your bundles are (as the scripts I've provided are only for publishing to a development environment) and you should be good.
Hope this is helpful to anyone else who runs into this issue.

TFS build server

We are just getting started with TFS 2010 and migration from SVN and CruiseControl.NET to TFS.
With cruisecontrol.NET we have a powershell script that does everything: copying, modifying, compressing files.
Now my question is how we can integrate that script into the TFS build server? Modifying the solution or creating a custom msbuild file?
Also I would like to combine this with Web Packaging. Any idea how this can be accomplished?
My recommendation is to create a custom msbuild file. In this file call build of your solution and then call your powershell script. Like:
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build">
<!-- Compile whole solution in release mode -->
<MSBuild
Projects="MySolutionFile.sln"
Targets="ReBuild"
Properties="Configuration=Release" />
<Exec
Command=“command_for_run_cutom_script“
ContinueOnError="false"
WorkingDirectory="." />
</Target>
</Project>
However consider rewriting your powershell script fully to msbuild script. You will get better maintenance. Copying, modifying, compressing files… are no problem for msbuild.
http://tfsccnetplugin.codeplex.com/ has all the documentation you need in terms of Configuring CCNet with TFS, as for the web packaging...unfortunately someone else will have to help with that.