FSharp build does not work in MSBuild, but works fine in Visual Studio

There are a number of projects in my solution, among which is also the F # project. Everything works fine in Visual Studio, but when I try to create it using MSBuild on my TeamCity server (which does not have VS installed), it generates the following build error:

C:\TeamCity\buildAgent\work\42c74d8b9d19a844\FSharpEngine\MY_FSHARP_PROJECT.fsproj : error MSB4057: The target "Clean" does not exist in the project. [16:27:58]Done Building Project "C:\TeamCity\buildAgent\work\42c74d8b9d19a844\Folder0\MY_FSHARP_PROJECT.fsproj" (Clean target(s)) -- FAILED. [16:27:58]Done Building Project "C:\TeamCity\buildAgent\work\42c74d8b9d19a844\Folder1\REFERENCING_FSHARP_PROJECT.csproj" (Clean target(s)) -- FAILED. [16:27:58]Done Building Project "C:\TeamCity\buildAgent\work\42c74d8b9d19a844\Folder2\UPPER_REFERENCING_FSHARP_PROJECT.csproj" (Rebuild target(s)) -- FAILED. [16:27:58]Done Building Project "C:\TeamCity\buildAgent\work\42c74d8b9d19a844\Folder4\UPPER_UPPER_REFERENCING_FSHARP_PROJECT.csproj.metaproj" (Rebuild target(s)) -- FAILED. [16:27:58]Done Building Project "C:\TeamCity\buildAgent\work\42c74d8b9d19a844\MY_SOLUTION.sln" (Rebuild target(s)) -- FAILED. [16:27:58]Done Building Project "C:\TeamCity\buildAgent\work\42c74d8b9d19a844\MY_SOLUTION.sln.teamcity" (TeamCity_Generated_Build target(s)) -- FAILED. 

I installed MSBuild Tools and the F # framework on my TeamCity server, but I still don't know why this error occurs.

Has anyone stumbled upon this error and can give me some clues on how to fix it? (I’ve lost the whole day and still no luck).

+7
visual-studio build f # msbuild teamcity
source share
3 answers

We had the same problem with AutoFixture.AutoFoq and ZeroToNine .

We did to modify the .fsproj files.

First you have to add

 <TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion> 

to the first <PropertyGroup> .

Secondly, you replace

 <Import Project="$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')" /> 

with this:

 <Choose> <When Condition="'$(VisualStudioVersion)' == '11.0'"> <PropertyGroup> <FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath> </PropertyGroup> </When> <Otherwise> <PropertyGroup> <FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath> </PropertyGroup> </Otherwise> </Choose> <Import Project="$(FSharpTargetsPath)" Condition="Exists('$(FSharpTargetsPath)')" /> 

Finally replace

 <Reference Include="FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 

from

 <Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"> 

If you want to see this in context, you can view the ZeroToNine commit that does the above .

+10
source share

You can create the target "Clean" in your project:

 <Target Name="Clean"> <MSBuild Targets="Clean" Projects=".\MySolutionDir\MySol.sln" Properties="Configuration=$(Configuration)" /> </Target> 

Or you can change the command line like this:

 MSBuild MyProj.proj /p:Configuration=Release;Targets=Clean 
+2
source share

Today I had a problem with the same symptoms on my build server. For me, this launched VS on the build server and created an F # project in which the F # toolkit was installed. By default, it was not installed completely.

0
source share

All Articles