Make a WebApplication project automatically publish on build

If you want to publish a Web Application project you can call MsBuild with parameters. Having a publish happen on each and every build - there is work to do. Visual Studio project files are MsBuild files since Version 2005. There is a way to force MsBuild and Visual Studio behave as requested. The project file needs to be edited slightly: <PropertyGroup> <PublishDestination>..\..\..\out\YourPublishDirectory</PublishDestination> </PropertyGroup> <Target Name="PublishToFileSystem" DependsOnTargets="PipelinePreDeployCopyAllFilesToOneFolder" AfterTargets="Build"> <MakeDir Condition="!Exists($(PublishDestination))" Directories="$(PublishDestination)" /> <ItemGroup> <PublishFiles Include="$(_PackageTempDir)\**\*.*" /> </ItemGroup> <Copy SourceFiles="@(PublishFiles)" DestinationFiles="@(PublishFiles->'$(PublishDestination)\%(RecursiveDir)%(Filename)%(Extension)')" SkipUnchangedFiles="True" /> </Target>

Basta 2015

It felt great to be and speak at Basta! again. Thanks to the organization and the audience.Here are my slides and samples:Defensive programming, resilience patterns & antifragility & Build

.NET Framework 4.6 Release

The new framework version is out. As with every new release it seems to me that the search indexes on Microsoft downloads have not been rebuilt yet. So I abuse this blog post and note the download links to myself…Microsoft .NET Framework 4.6 (Offline Installer) for Windows Vista SP2, Windows 7 SP1, Windows 8, Windows 8.1, Windows Server 2008 SP2 Windows Server 2008 R2 SP1, Windows Server 2012 and Windows Server 2012 R2 Microsoft Build Tools 2015Windows 10 and .NET Framework 4.6 SDKIntelliTrace Collector for Visual Studio 2015 (Just replace the Version number in the Installation Path)

Maven Archetypes in IntelliJ

IntelliJ has the ability to use Maven as build and project system. The concept of an archetype is a predefined project or project template.When “File | New project” is used to create a new project and “Maven” is selected the following dialog is displayed:IntelliJ comes with a few archetypes but of course custom ones can be added. On the MVN Repository for example several archetypes for Wildfly are available: XML snipped can be used as copy-paste-source for IntelliJ’s “Add archetype dialog”:After clicking the “OK” button the newly added archetypes are available as a source for the project creation. The custom archetypes are stored in the file “C:\{username}\Daniel\.IntelliJIdea{version}\system\Maven\Indices\UserArchetypes.xml” on Windows and “~/.IntelliJIdea{version}/system/Maven/Indices/UserArchetypes.xml” on Linux. Next define group and artifact identifier as well as version for the new project:Select the Maven version:And the project location:The result is a runnable quick start for working with the Wildfly application server.

.NET Licensing - ode to monolithic applications?

The Microsoft .NET Framework has a built in licensing technology. It can be found in the namespace System.ComponentModel and System.ComponentModel.Design. Here is a small sample implementation of the minimal required classes: A lot of component producers use this licensing model – so does Tx Text Control – the component that I wanted to use. As a user you just create a *.licx-file, include it into the project as “embedded resource” and add the components that should be licensed by their fully qualified type names – one per line: During the build the LC-Task executes the license compiler (LC.exe). The license compiler is part of the .NET SDK that is part of the Windows SDK. If you have the Windows SDK 8.1 or Visual Studio 2013 installed it can be found at “C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1A\bin\NETFX 4.5.1 Tools\”. The result is the “Licensing.dll.licenses” file that is embedded by the C#-Compiler (Csc.exe) in the next step. During runtime the LicenseProvider-attribute is evaluated and the defined license provider is handed over to the System.ComponentModel.LicenseManager’s Validate method. This call forwards to the internal method ValidateInternalRecursive which then calls the GetLicense method of the LicenseProvider. The first argument of the GetLicenseCall is of type LicenseContext and at runtime filled with the static held instance of the internal class RuntimeLicenseContext. To resolve the license key the method GetSavedLicenseKey is called on the LicenseContext. The implemention offers two options to resolve the key: Resolve from URI: new Uri(new Uri(AppDomain.CurrentDomain.SetupInformation.ApplicationBase), AppDomain.CurrentDomain.SetupInformation.LicenseFile) Resolve from Embedded Resource: The lookup on references/loaded assemblies is only processed, if there is NO entry assembly - for instance within ASP.NET that is the case. But my intend was to create a build task for MsBuild that converts Microsoft Word’s DOCX files into PDF documents. So I have an entry assembly (MsBuild.exe). The entry assembly knows nothing about TX TextControl – and that is a good thing! I have no control over the entry assembly (MsBuild.exe). A situation I guess to find in every composite UI/modular desktop application. No wonder the monolith is often the preferred architecture especially on the desktop! After an intense debugging session through the framework sources (supported by red gate’s Reflector) I wrote a small helper class. WARNING: I use reflection to access internal types and private fields and modify their values – this means: If Microsoft decides to change their internal implementation it might not work anymore. But as we as can see the code was written for .NET 1.0 and has not been updated in the last 10 years: It’s not very likely that changes will happen. Now I just need to call LicenseLoader.LoadLicensesFromCallingAssembly() before the Tx Text Control component is instantiated the first time and everything works as expected. HTH

Fixing Msbuild Error msb3247 - Found conflicts between different versions of the same dependent assembly.

Set MsBuild Verbosity to find out which assemblies conflict: msbuild.exe .\Compile.msbuild /verbosity:detailed ... There was a conflict between "xxx, Version=, Culture=neutral, PublicKeyToken=xxx" and "xxx, Version=1.0.12152.1, Culture=neutral, PublicKeyToken=xxx". "xxx, Version=, Culture=neutral, PublicKeyToken=xxx" was chosen because it was primary and "xxx, Version=1.0.12152.1, Culture=neutral, PublicKeyToken=0313e76cb5077f22" was not. References which depend on "xxx, Version=, Culture=neutral, PublicKeyToken=xxx" [D:\Projects\abc\bin\xxx.dll]. D:\Projects\abc\bin\xxx.dll Project file item includes which caused reference "D:\Projects\abc\src\Web.BuildServer\bin\xxx.dll". xxx References which depend on "xxx, Version=1.0.12152.1, Culture=neutral, PublicKeyToken=xxx" []. D:\Projects\abc\src\packages\yyy\lib\Net40\yyy.dll Project file item includes which caused reference "D:\Projects\abc\src\packages\yyy\lib\Net40\yyy.dll". yyy ... What means yyy references a version of yyy other than the one references by the project or another assembly. Check the Config files For Web-Applications the Web.config for all other project types the App.config file (even for class libraries). Make sure you don’t have a <runtime> section pointing to the wrong assembly version. Fix the error by binding the correct version. <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31BF3856AD364E35" culture="neutral"/> <bindingRedirect oldVersion="" newVersion=""/> </dependentAssembly> </assemblyBinding> </runtime> </configuration> Helpful utilities

MsBuild finding directories if not given as parameter

I’m a lazy developer. Being lazy does not mean I avoid to work. It means that I like to reflect things I am doing and optimize and atomize stuff to get more time on the valuable tasks. Code generation is a tool I tend to use quite regularly and T4 is at most my generator of choice. Generated files can cause a lot of merging conflicts. So they are not to be checked into my source control system (currently my choice is HG/Mercurial). For the build server this means the files do not exist when the repository is freshly checked out – they need to be generated during the build right before the compile happens. With code generation I usually tend to use a pattern that is for example also used by ASP.NET MVC Views/Controller generation: If there is a local directory containing code generation templates, use it. Otherwise utilize the system wide templates. MsBuild version 4.0 comes with a feature called property functions. This allows to place for instance a “find directories” inside a property group. I use them to: Allow to set a system wide template directory using the command line/the MsBuild API. If no directory is set use a local directory. If non of the above is applied set a fallback default. Here is the XML snippet that shows how to use the pattern: <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Generate" ToolsVersion="4.0" xmlns=""> <PropertyGroup> <RootFolder>..\src</RootFolder> <CodeGeneratorDir Condition=" '$(CodeGeneratorDir)' == '' " /> <LocalCodeGeneratorDir> CodeGenerationTemplates </LocalCodeGeneratorDir> <CodeGeneratorDirFallback> C:\CodeGenerationTemplates </CodeGeneratorDirFallback> </PropertyGroup> <ItemGroup> <ModelFiles Include="..\src\**\*.xdml" /> <TemplateDirectory Include="$(CodeGeneratorDir);" /> <TemplateDirectory Condition=" '$(CodeGeneratorDir)' == '' " Include="$([System.IO.Directory]::GetDirectories( &quot;$(RootFolder)&quot;, &quot;$(LocalCodeGeneratorDir)&quot;, System.IO.SearchOption.AllDirectories))" /> <TemplateDirectory Condition=" '@(TemplateDirectory)' == '' " Include="$(CodeGeneratorDirFallback)" /> </ItemGroup> <Target Name="Generate"> <Message Text="@(TemplateDirectory)" /> <Message Text="@(ModelFiles)" /> </Target> </Project>