Specify assembly version number as a command line argument in MSBuild

For SDK-style projects that are built using dotnet.exe, assembly version attributes are generated automatically, so you can use /p:Version=5.4.3.0 right out of the box. If you use the old project format, you need to add the following BeforeBuild step to your .csproj file. No need to use extra .targets and extension packs, because MSBuild already … Read more

_CopyWebApplication with web.config transformations

I’ve been hitting my head against the wall for this. After hiking through the MSBuild targets I’ve come across something very “opaque”. Long story short: Try using the new _WPPCopyWebApplication. It works on my machine. The old _CopyWebApplication does not support transformations for legacy reasons. This is what I do: msbuild /t:Rebuild /p:OutDir=..\publish\;Configuration=Release;UseWPP_CopyWebApplication=True;PipelineDependsOnBuild=False MvcApplication1\MvcApplication1.csproj # … Read more

csc error cs0006 metadata file could not be found building a .net 3.5 application with TFS 2012

The project dependencies and project build order can be specified in Visual Studio 2012 by right clicking on the project in the solution explorer and selecting Project Dependencies. By doing this action, your solution file will be fixed. In my case I was able to fix this problem without manually editing the solution files.

How do I call Visual Studio 2017 RC’s version of MSBuild from a BAT file?

The supported way VS2017’s setup engine has an interop API that allows you to query information about which instance(s) of VS2017 are installed. There’s a NuGet package for it, and even a sample of how to query, including the installation path. For consumption in a batch or PS file, you might just rewrite the sample … Read more

Path to SignTool.exe or “Windows Kits” directory when using Visual Studio 2012

I just ran into the same issue. Running the build from a Visual Studio 2012 Command Prompt worked, but it was failing in the IDE. Looking for a detailed or diagnostic log led me to What is the default location for MSBuild logs?, which told me that Visual Studio can’t give the diagnostic information I … Read more

In MSBuild, can I use the String.Replace function on a MetaData item?

You can do this with a little bit of trickery: $([System.String]::Copy(‘%(Filename)’).Replace(‘config’,”)) Basically, we call the static method ‘Copy’ to create a new string (for some reason it doesn’t like it if you just try $(‘%(Filename)’.Replace(‘.config’,”))), then call the replace function on the string. The full text should look like this: <Target Name=”Build”> <Message Text=”@(Files->’$([System.String]::Copy(&quot;%(Filename)&quot;).Replace(&quot;.config&quot;,&quot;&quot;))’)” /> … Read more

MSBuild deploy failing after upgrade to .NET 4.5

In this case you will need to specify the MSBuild property VisualStudioVersion=11.0. I just blogged about this at http://sedodream.com/2012/08/19/VisualStudioProjectCompatabilityAndVisualStudioVersion.aspx, I’ve pasted it below as well for your convenience. One of the most requested features of Visual Studio 2012 was the ability to open projects in both VS 2012 as well as VS 2010 (requires VS … Read more

how to replace string in file using msbuild?

This is no longer required… you can now inject C# into the project/build file… Define a custom task and parameters as follows: <UsingTask TaskName=”ReplaceFileText” TaskFactory=”CodeTaskFactory” AssemblyFile=”$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll”> <ParameterGroup> <InputFilename ParameterType=”System.String” Required=”true” /> <OutputFilename ParameterType=”System.String” Required=”true” /> <MatchExpression ParameterType=”System.String” Required=”true” /> <ReplacementText ParameterType=”System.String” Required=”true” /> </ParameterGroup> <Task> <Reference Include=”System.Core” /> <Using Namespace=”System” /> <Using Namespace=”System.IO” /> <Using … Read more

MSBuild echo task?

MsBuild has the Message task built in which will output a string to the console: <Target …> <Message Text=”text to output” /> </Target> By default, MSBuild logs at minimal verbosity which will prevent these messages from being seen. Either increase the verbosity, or set the Message‘s Importance parameter to high: <Target …> <Message Text=”text to … Read more