Using the Windows Credential Manager from MsBuild

Today I needed to make a web service call with authentication from MsBuild. Of course storing the credentials in plain text is not an option.The Windows Credential Manager User Interface can be opened by running the command:control /name Microsoft.CredentialManagerThere is also a command line interface:cmdkey.exeAs the Windows APIs are not provided as wrapper through the BCL a NuGet package comes to help:nuget.exe install CredentialManagementFinally everything wrapped up in a MsBuild Task:

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 & antifragilityhttp://www.slideshare.net/lennybacon/2015-basta-2015-de-defensive-programming-resilience-patterns-antifragilityhttps://github.com/lennybacon/resilience-patterns-jshttps://github.com/lennybacon/resilience-patterns-tsJavaScript & Buildhttp://www.slideshare.net/lennybacon/2015-basta-2015-de-javascript-und-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: http://mvnrepository.com/artifact/org.wildfly.archetypeThe 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: http://msdn.microsoft.com/en-us/library/ms164311.aspx msbuild.exe .\Compile.msbuild /verbosity:detailed ... There was a conflict between "xxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxx" and "xxx, Version=1.0.12152.1, Culture=neutral, PublicKeyToken=xxx". "xxx, Version=1.0.0.0, 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=1.0.0.0, 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="0.0.0.0-2.0.0.0" newVersion="1.0.0.0"/> </dependentAssembly> </assemblyBinding> </runtime> </configuration> Helpful utilities https://github.com/mikehadlow/AsmSpy