Build error on Jenkins calling F# compiler with --targetprofile parameter - jenkins

We are building an Azure solution on Jenkins. This contains several F# projects, a Azure Cloud deployment project, and a C# Azure worker role.
On developer boxes it builds fine. When building on Jenkins we get:
"C:\Program Files (x86)\Jenkins\jobs\REDACTED.sln" (Clean;Build target) (1) ->
"C:\Program Files (x86)\Jenkins\jobs\REDACTED QA\workspace\REDACTED\REDACTED.csproj" (default target) (5:4) ->
"C:\Program Files (x86)\Jenkins\jobs\REDACTED QA\workspace\REDACTED.FSharp.AWS.S3\REDACTED.FSharp.AWS.S3.fsproj" (default target) (6:6) ->
(CoreCompile target) ->
FSC : error FS1052: Invalid value 'Qa' for '--targetprofile', valid values are 'mscorlib' or 'netcore'. [C:\Program Files (x86)\Jenkins\jobs\REDACTED QA\workspace\REDACTED.FSharp.AWS.S3\REDACTED.FSharp.AWS.S3.fsproj]
The problem seems to be something to do with an MSBuild parameter called 'TargetProfile' we need for the Azure aspects to specify which configuration to use (e.g. UAT or QA) and an undocumented F# parameter called --targetprofile which expects the values mscorlib or netcore.
We'd probably like a workaround which decouples these two usages of 'targetprofile'. Ideally we'd like not to have to fiddle with things like F#'s targets file as obviously we'd have to remember to apply this in all the places we might build now and in the future.

Blah, collision between MSBuild property names.
Maybe you can work around by defining a target in your project that runs directly before the F# compile target, and sets the F# TargetProfile to mscorlib, then also define a target that runs directly after F# compile that swaps the value back to whatever it was before.
From a quick test this seems to work ok.
<?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="3.5">
<PropertyGroup>
<!-- assume TP has Azure-specific value -->
<TargetProfile>QA</TargetProfile>
</PropertyGroup>
<Target Name="BeforeFSharpCompile" BeforeTargets="CoreCompile">
<PropertyGroup>
<TempTargetProfile>$(TargetProfile)</TempTargetProfile>
<TargetProfile>mscorlib</TargetProfile>
</PropertyGroup>
<Message Text="Swapped from $(TempTargetProfile) to $(TargetProfile)" />
</Target>
<Target Name="AfterFSharpCompile" AfterTargets="CoreCompile">
<PropertyGroup>
<TargetProfile>$(TempTargetProfile)</TargetProfile>
</PropertyGroup>
<Message Text="Swapped back to $(TargetProfile)" />
</Target>
</Project>

Related

How do I specify a target architecture when building projects in Visual Studio code?

I am new to VS code/F# and I am trying to build a F# console app (on both Windows workstation and on my Linux computer).
I installed the Ionide extension together with FAKE.
The code I am considering is the Iris example (see How to translate the intro ML.Net demo to F#?), creating a New F# Project with Ionide and using Microsoft.ML.
My iris.fsproj is
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net461</TargetFramework>
<DebugType>portable</DebugType>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
</PropertyGroup>
<ItemGroup>
<Compile Include="iris.fs" />
<None Include="App.config" />
</ItemGroup>
<Import Project="..\.paket\Paket.Restore.targets" />
</Project>
When running the script (which I do with the "play" button aka F#: run script provided with VS Code/Ionide) I get:
C:\Users\MyUser\.nuget\packages\microsoft.ml\0.2.0\build\Microsoft.ML.targets(16,5): error : Microsoft.ML currently supports 'x64' processor architectures. Please ensure your application is targeting 'x64'.
together with
Running build failed.
Error:
System.Exception: dotnet build failed
How do I target x64 with the project structure provided by Ionide?
It should be as simple as adding the following line to your PropertyGroup section:
<PlatformTarget>x64</PlatformTarget>
There are more complicated setups possible using the Condition attribute to set the platform target based on various command-line arguments to the compiler, but that should be the simplest way to get you up and running.

Getting an error during the deploying webapplication "Could not open Source file: Could not find a part of the path"

I got an error during the deploying my web-application.
The title of error is Could not open Source file: Could not find a part of the path
'Could not open Source file: Could not find a part of the path
'E:\ARCHIVES\Projects\Main\Jahan.Handicraft\Jahan.Handicraft.Web.Mvc.UmbracoCms.App\obj\Release\AspnetCompileMerge\TempBuildDir\App_Plugins\UmbracoForms\Data\Web.config;\App_Plugins\UmbracoForms\Data\Web.config'.'.
I've used Umbraco 7.4.3 und ASP.NET MVC in my project.
I'd like deploy it on localhost.
How can I solve this problem?
This is a failed attempt at transforming connection strings in sublevel configurations files.
To disable this transformation, edit the publish profile under Properties\PublishProfiles and set the value of the AutoParameterizationWebConfigConnectionStrings element to false. Add the element if missing.
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!--
...
Other settings
...
-->
<AutoParameterizationWebConfigConnectionStrings>false</AutoParameterizationWebConfigConnectionStrings>
</PropertyGroup>
</Project>
I got it from this blog (which is not mine): http://blog.aabech.no/archive/web-deploy-says-could-not-open-source-file-some-webconfig-when-you-publish-an-umbraco-site/
Post installation
You should note that the Umbraco nuget package adds a build step to always include the Umbraco folders when you deploy using Web One-Click Publish with Visual Studio.
You can see these folders in packages/UmbracoCms x.y.z/build/UmbracoCms.targets
Should you need to exclude any of these folders or content, you can add a target to your .pubxml files in the properties/Publish folder. For instance if you need to exclude json data a plugin generates during production.
<Target Name="StopUmbracoFromPublishingAppPlugins" AfterTargets="AddUmbracoFilesToOutput">
<ItemGroup>
<FilesForPackagingFromProject Remove=".\App_Plugins\UmbracoForms\Data\**\*.*"/>
</ItemGroup>
</Target>
Reference: https://our.umbraco.org/documentation/Getting-Started/Setup/Install/install-umbraco-with-nuget#post-installation

Pass parameters with msbuild task

I am trying to create a build script, to migrate our build process from Cruise Control to jenkins, and I can't see how to get access to all the normal command line parameters when I call the MSBuild task.
For instance I would like to run the equivalent of
msbuild common.sln /p:Platform="$(MsBuildPlatformAnyCpu)" /p:Configuration=$(MsBuildConfiguration) /v:$(MsBuildVerbosity) /p:WarningLevel=$(MsBuildWarningLevel);OutputPath="$(ProjectBinariesFolder)" /fileLogger /flp1:logfile=$(ProjectBuildLogsFolder)\$(ProjectFile)_BuildErrors.txt;errorsonly /flp2:logfile=$(ProjectBuildLogsFolder)\$(ProjectFile)_BuildWarnings.txt;warningsonly /flp3:LogFile=$(ProjectBuildLogsFolder)\$(ProjectFile)_Build.txt;Verbosity=diagnostic
This is my msbuild file:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0" DefaultTargets="Build">
<PropertyGroup>
<JenkinsBuildFolder>C:\Program Files (x86)\Jenkins\jobs\build2\workspace</JenkinsBuildFolder>
<ProjectSourcesFolder>$(JenkinsBuildFolder)\Sources</ProjectSourcesFolder>
<ProjectBinariesFolder>$(JenkinsBuildFolder)\Binaries</ProjectBinariesFolder>
<ProjectBuildLogsFolder>$(JenkinsBuildFolder)\BuildLogs</ProjectBuildLogsFolder>
<ProjectTestLogsFolder>$(JenkinsBuildFolder)\TestLogs</ProjectTestLogsFolder>
<ProjectGuid>{F8A25B4A-589A-4D3D-A568-4700FD776250}</ProjectGuid>
</PropertyGroup>
<ItemGroup>
<ProjectToBuild Include="Common.sln">
<Properties>OutputPath=$(ProjectBinariesFolder);Configuration=Build</Properties>
</ProjectToBuild>
</ItemGroup>
<Target Name="Build">
<MSBuild Projects="#(ProjectToBuild)" />
</Target>
</Project>
However I have no idea how to get the task equivalent properties of the command line switches /v /filelogger etc
You can't.
/p is used to inject properties into the build from the command line. The other command line options like /v are specific to the build process and you cannot move them to the proj file.
Note that there was probably good reason why your Cruise Control setup specified those /p params. I suspect it is because the values for those params are defined in Cruise Control and it is a way to parametrize the build - so one could kick off a build and say $(MsBuildConfiguration) = "Debug". You may want to do the same with Jenkins and not hardcore the values.
As for the /p params, Jenkins allows you pass parameters to msbuild - see Default parameters below.

Why won't my msbuild deploy work after I check "Precompile during publishing" on the publish properties?

I checked the middle option, below, "Precompile during publishing".
This changed the FDeploy.pubxml file by a few lines. Fine. I committed this single change to my build server.
Heres the pubxml:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>Any CPU</LastUsedPlatform>
<SiteUrlToLaunchAfterPublish />
<LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
<ExcludeApp_Data>False</ExcludeApp_Data>
<publishUrl>C:\Temp</publishUrl>
<DeleteExistingFiles>True</DeleteExistingFiles>
<PrecompileBeforePublish>True</PrecompileBeforePublish>
<EnableUpdateable>False</EnableUpdateable>
<DebugSymbols>False</DebugSymbols>
<WDPMergeOption>DonotMerge</WDPMergeOption>
</PropertyGroup>
</Project>
The remote build with mvcbuildviews enabled passed. The remote deploy failed with errors like:
Error 82 The name 'ViewBag' does not exist in the current context
Error 5 The name 'model' does not exist in the current context
and so on. There's over 100 errors like this. Keep in mind the regular msbuildviews enabled msbuild step worked fine with the same code.
I use msbuild on the web project csproj this way:
/p:DeployOnBuild=true /p:PublishProfile=FDeploy /p:VisualStudioVersion=12.0 /p:Configuration=Release
Any clues? Oh yeah, checking the box caused the same errors on my dev machine as well, I had to delete the bin, obj and appdata folders completely to neutralize it. However, doing a fresh checkout on the build server did not help.
Also note that when I went back to my old deploy profile it took a fresh checkout to fix the deploy.
I had to cheat to solve this problem: I restricted my use of MvcBuildViews to only the 'Debug' version of the project:
In the csproj file:
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<MvcBuildViews>true</MvcBuildViews>
</PropertyGroup>
I ran into other inexplicable errors using mvcbuildviews when deploying. Seems best to avoid using it altogether. Anyway, the build is still kept clean because I compile and test the debug version too.

Adding files to the bin directory at Build and Publish

I have two license files that I would like to include in my \bin directory both when I build and publish.
Both files are in the App_Data directory (their initial location doesn't matter, they just need to end up in the \bin) and have the following properties set:
Build Action = Content
Copy to Output Directory = Copy Always
They are in not the \bin when I build or publish.
What is wrong with my setup: the settings, the folders, the files, something else...?
UPDATE
I moved the files out of the App_Data directory and placed them in the project root and now they are copied to the \bin on build.
I've done this in a few projects by expanding my .csproject file slightly. The following code should be put directly beneath the Project node in your WebProject.csproj.
The AfterBuild target simply copies a set of files ("unreferenced DLLs" in this case) to the bin-folder when building normally from Visual Studio. The CustomCollectFiles basically do the same thing when deploying.
<PropertyGroup>
<UnreferencedDlls>..\lib\Unreferenced\**\*.dll</UnreferencedDlls>
</PropertyGroup>
<PropertyGroup>
<CopyAllFilesToSingleFolderForPackageDependsOn>
CustomCollectFiles;
$(CopyAllFilesToSingleFolderForPackageDependsOn);
</CopyAllFilesToSingleFolderForPackageDependsOn>
</PropertyGroup>
<Target Name="AfterBuild">
<Message Text="Copying unreferenced DLLs to bin" Importance="High" />
<CreateItem Include="$(UnreferencedDlls)">
<Output TaskParameter="Include" ItemName="_UnReferencedDLLs" />
</CreateItem>
<Copy SourceFiles="#(_UnReferencedDLLs)" DestinationFolder="bin\%(RecursiveDir)" SkipUnchangedFiles="true" />
</Target>
<Target Name="CustomCollectFiles">
<Message Text="Publishing unreferenced DLLs" Importance="High" />
<ItemGroup>
<_CustomFiles Include="$(UnreferencedDlls)" />
<FilesForPackagingFromProject Include="%(_CustomFiles.Identity)">
<DestinationRelativePath>bin\%(RecursiveDir)%(Filename)%(Extension)</DestinationRelativePath>
</FilesForPackagingFromProject>
</ItemGroup>
</Target>
The part you need to modify is basically the UnreferencedDlls node to match your folder structure. The **\*.dll part simply means "every DLL file at any level beneath here".
If you're using Visual Studio:
Show your file properties (Click on your file or Right-click on it then choose Properties)
At the Copy to Output Directory property choose Copy always or Copy if newer.
At build time, the file is going to be copied at the bin directory: Debug or Release...
not necessarily a direct answer, but I highly suggest not using the baked in "publish" mechanism, but rather wire up a build script (probably in powershell) that will do everything you need. It's really easy to hook into MSBuild as well as nUnit and also copy files and move them around.
POWERSHELL (rough) example.
# Get Directory Location
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
# Build the application using MSBuild
cmd /c C:\Windows\Microsoft.NET\Framework\$v4_net_version\msbuild.exe "$directorypath\MyProject.sln" /p:Configuration=Release
# Run the tests using nUnit
cmd /c $directorypath\build\nunit\nunit-console.exe $solutionPath\MyProject.Tests\bin\debug\MyProject.Tests.dll
# Copy the license to the appropriate directory
Copy-Item -LiteralPath "$directorypath\mylicensefile.txt" "$directorypath\bin\release" -Force
# NOTE: You are going to have to adjust this to match your solution and projects.
In this post on Microsoft Connect the answer is much simpler:
Referenced assemblies in Unit Test are not copied in TestResults/Out
So what I did was the following:
[TestClass]
[DeploymentItem("Some.dll")]
public class SomeTests
{
...
}
It works fine for me.
Hope it help.

Resources