8

I have a number of projects in my solution, among which also a F# project. Everything builds fine in Visual Studio, but when I try to build it with MSBuild on my TeamCity server (which does not have VS installed) it throws 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 have installed MSBuild Tools and F# framework on my TeamCity server, but I still don't know why this error is thrown.

Did someone came across this error and can give me some clues on how to fix it? (I've lost a day already and still no luck).

Tamas Ionut
  • 4,240
  • 5
  • 36
  • 59
  • Actually both the below answers helped: since I had to change the FSharpVersion from 4.3.0.0 to Version and I had to added Clean target to the FSharp project. Thanks alot to both of you! – Tamas Ionut Mar 12 '14 at 12:50

3 Answers3

12

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

What we did was to modify the .fsproj files.

First, you have to add

<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>

to the first <PropertyGroup>.

Second, 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">

with

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

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

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
Mark Seemann
  • 225,310
  • 48
  • 427
  • 736
  • If you could have a look on this one http://stackoverflow.com/questions/22357735/fsharp-project-build-fails-in-msbuild-in-teamcity I would be definitely own you a couple of cold ones (similar problem) – Tamas Ionut Mar 12 '14 at 16:23
  • Sorry, I looked, but I haven't seen that error before (and it doesn't ring a bell either). – Mark Seemann Mar 12 '14 at 17:10
  • I had a different problem. The fsproj file was updated as you show, but I was getting the error on my build server, where VS wasn't installed. I ended up cheating and copying the FSharp folder from another machine. – Benjol Nov 17 '15 at 09:42
3

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 modify the command line to something like this:

MSBuild MyProj.proj /p:Configuration=Release;Targets=Clean
John Willemse
  • 6,608
  • 7
  • 31
  • 45
  • This was needed indeed, but also there were some problems with the FSharp.Core (see @Mark's answer). – Tamas Ionut Mar 12 '14 at 12:51
  • Also made a follow-up of this issue here: http://stackoverflow.com/questions/22357735/fsharp-project-build-fails-in-msbuild-in-teamcity. If you wanna take a look, I would be really gratefull :) – Tamas Ionut Mar 12 '14 at 16:25
0

I had a problem today with the same symptoms on my build server. What fixed it for me was starting up VS on the build server and creating a F# project, which installed the F# tooling. It was not installed completely by default.

Johan Franzén
  • 2,355
  • 1
  • 17
  • 15