FSharp构建在MSBuild中失败,但在Visual Studio中正常工作

时间:2014-03-12 10:03:51

标签: visual-studio build msbuild f# teamcity

我的解决方案中有很多项目,其中还有一个F#项目。一切都在Visual Studio中构建良好,但是当我尝试在我的TeamCity服务器(没有安装VS)上使用MSBuild构建它时,它会抛出以下构建错误:

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.

我已经在我的TeamCity服务器上安装了MSBuild工具和F#框架,但我仍然不知道为什么会抛出此错误。

是否有人遇到此错误并可以提供一些有关如何修复它的线索? (我已经失去了一天,但仍然没有运气)。

2 个答案:

答案 0 :(得分:10)

我们在AutoFixture.AutoFoqZeroToNine时遇到了同样的问题。

我们所做的是修改.fsproj文件。

首先,您必须添加

<TargetFSharpCoreVersion>4.3.0.0</TargetFSharpCoreVersion>

到第一个<PropertyGroup>

其次,您替换

<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')" />

用这个:

<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)')" />

最后,替换

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

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

如果您想在上下文中看到这一点,可以查看the ZeroToNine commit that does the above

答案 1 :(得分:0)

今天我的构建服务器上出现了相同症状的问题。为我修复的是在构建服务器上启动VS并创建一个F#项目,它安装了F#工具。默认情况下,它未完全安装。