【问题标题】:FSharp project build fails in MSBuild in TeamCityTeamCity 的 MSBuild 中的 FSharp 项目构建失败
【发布时间】:2014-04-16 22:54:16
【问题描述】:

我在here 中描述了以下设置(安装了 MSBuild 和 F# 3.1 工具的 TeamCity)。

我的解决方案中有许多项目,其中还有一个 F# 项目。在 Visual Studio 中一切正常,但是当我尝试在我的 TeamCity 服务器(未安装 VS)上使用 MSBuild 构建它时,它会在引用我的 FSharp 项目的项目上引发以下构建错误

"C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9\MY_SOLUTION.sln.teamcity" (TeamCity_Generated_Build target) (1) ->
[17:04:14]"C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9\MY_SOLUTION.sln" (Build target) (2) ->
[17:04:14]"C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9\Folder 0\ONE_PROJECT.csproj.metaproj" (default target) (3) ->
[17:04:14]"C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9\Folder 1\ANOTHER.csproj" (default target) (4) ->
[17:04:14]"C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9\Folder 2\REFERENCING_PROJECT.csproj" (default target) (7) ->
[17:04:14](CoreCompile target) -> 
[17:04:14]  SOME_CLASS_IN_REFERENCING_PROJECT.cs(10,7): error CS0246: The type or namespace name 'MY_FSHARP_PROJECT_NAME' could not be found (are you missing a using directive or an assembly reference?) [C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9\Folder 2\REFERENCING_PROJECT.csproj]
[17:04:14] ... AND a bunch of similar errors here.

但是,我在构建 MY_FSHARP_PROJECT_NAME(FSharp 项目)时没有发现任何错误,所以我猜构建过程正常。 这是我在构建项目中遇到的唯一错误。 我安装了 F# 3.1 工具 (FSharp.Core 4.3.1.0)。

有人遇到过这类问题吗?

这是来自 TeamCity 的构建日志:

Step 2/3: 2. Build Solution (MSBuild) (10s)
[13:57:31][Step 2/3] Starting: C:\TeamCity\buildAgent\plugins\dotnetPlugin\bin\JetBrains.BuildServer.MsBuildBootstrap.exe /workdir:C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9 "/msbuildPath:C:\Program Files (x86)\MSBuild\12.0\bin\MSBuild.exe"
[13:57:31][Step 2/3] in directory: C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9
[13:57:35][Step 2/3] SOLUTION.sln.teamcity: Build target: TeamCity_Generated_Build (5s)
[13:57:35][SOLUTION.sln.teamcity] TeamCity_Generated_Build (5s)
[13:57:35][TeamCity_Generated_Build] MSBuild (5s)
[13:57:35][MSBuild] SOLUTION.sln: Build targets: Clean;Build (5s)
[13:57:35][SOLUTION.sln] ValidateSolutionConfiguration
[13:57:35][SOLUTION.sln] ValidateProjects
[13:57:35][SOLUTION.sln] Clean (2s)
[13:57:36][Step 2/3] C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.CSharp.CurrentVersion.targets(388, 5): warning MSB4011: "C:\Program Files (x86)\MSBuild\12.0\bin\Microsoft.Common.targets" cannot be imported again. It was already imported at "C:\Program Files (x86)\Microsoft SDKs\F#\3.1\Framework\v4.0\Microsoft.FSharp.Targets (203,5)". This is most likely a build authoring error. This subsequent import will be ignored. [C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9\FSHARP_PROJECT\Infotron.FSHARP_PROJECT.fsproj]
[13:57:33][Step 2/3] MSBuild command line parameters contain "/property:" or "/p:". It is recommended to define System Property on Build Parameters instead.
[13:57:38][SOLUTION.sln] Build (2s)
[13:57:38][Build] MSBuild (2s)
[13:57:38][MSBuild] SOME_FOLDER3\Nl.SOME_PARENT_REFERENCING_PROJ.UI.csproj.metaproj: Build default targets (2s)
[13:57:38][SOME_FOLDER3\Nl.SOME_PARENT_REFERENCING_PROJ.UI.csproj.metaproj] Build (2s)
[13:57:38][Build] MSBuild (2s)
[13:57:38][MSBuild] SOME_FOLDER\SOME_PARENT_REFERENCING_PROJ.csproj: Build default targets (2s)
[13:57:38][SOME_FOLDER\SOME_PARENT_REFERENCING_PROJ.csproj] ResolveProjectReferences (2s)
[13:57:38][ResolveProjectReferences] MSBuild (2s)
[13:57:38][MSBuild] SOME_FOLDER2\PROJECT2.csproj: Build default targets (1s)
[13:57:39][MSBuild] FormulaTransformation\REFERENCING_FSHARPPROJ_PROJECT.csproj: Build default targets
[13:57:39][FormulaTransformation\REFERENCING_FSHARPPROJ_PROJECT.csproj] ResolveProjectReferences
[13:57:39][FormulaTransformation\REFERENCING_FSHARPPROJ_PROJECT.csproj] GenerateTargetFrameworkMonikerAttribute
[13:57:39][FormulaTransformation\REFERENCING_FSHARPPROJ_PROJECT.csproj] CoreCompile
[13:57:39][CoreCompile] Csc
[13:57:39][Csc] C:\Program Files (x86)\MSBuild\12.0\bin\Csc.exe /noconfig /nowarn:1701,1702 /nostdlib+ /errorreport:prompt /warn:4 /define:DEBUG;TRACE /highentropyva+ /reference:C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9\SOME_FOLDER2\bin\Debug\SOME_FOLDER2.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\FSharp.Core.dll" /reference:C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9\lib\Irony.dll /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\Microsoft.CSharp.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\mscorlib.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Core.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.DataSetExtensions.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Data.Entity.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.dll" /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5\System.Xml.Linq.dll" /reference:C:\TeamCity\buildAgent\work\9d3b5b7177ddb2b9\Util\bin\Debug\Util.dll /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\FormulaTransformation.dll /subsystemversion:6.00 /target:library /utf8output REFERENCING_FSHARPPROJ_CLASS.cs Properties\AssemblyInfo.cs "C:\TeamCity\buildAgent\temp\buildTmp\.NETFramework,Version=v4.5.AssemblyAttributes.cs"
[13:57:40][Csc] REFERENCING_FSHARPPROJ_CLASS.cs(10, 7): error CS0246: The type or namespace name 'SOME_CLASS_FROM_FSHARP_PROJ' could not be found (are you missing a using directive or an assembly reference?)
[13:57:40][Csc] REFERENCING_FSHARPPROJ_CLASS (**this class is in the project that references the FSharp project and calls SOME_CLASS_FROM_FSHARP_PROJ class from FSharp project**).cs(38, 16): error CS0246: The type or namespace name 'SOME_CLASS_FROM_FSHARP_PROJ' could not be found (are you missing a using directive or an assembly reference?)
[13:57:40][Csc] REFERENCING_FSHARPPROJ_CLASS.cs(154, 24): error CS0246: The type or namespace name 'SOME_CLASS_FROM_FSHARP_PROJ' could not be found (are you missing a using directive or an assembly reference?)
[13:57:40][Csc] REFERENCING_FSHARPPROJ_CLASS.cs(192, 78): error CS0246: The type or namespace name 'SOME_CLASS_FROM_FSHARP_PROJ' could not be found (are you missing a using directive or an assembly reference?)
[13:57:40][Csc] REFERENCING_FSHARPPROJ_CLASS.cs(192, 28): error CS0246: The type or namespace name 'SOME_CLASS_FROM_FSHARP_PROJ' could not be found (are you missing a using directive or an assembly reference?)
[13:57:40][Csc] REFERENCING_FSHARPPROJ_CLASS.cs(229, 32): error CS0246: The type or namespace name 'SOME_CLASS_FROM_FSHARP_PROJ' could not be found (are you missing a using directive or an assembly reference?)
[13:57:40][Csc] REFERENCING_FSHARPPROJ_CLASS.cs(252, 16): error CS0246: The type or namespace name 'SOME_CLASS_FROM_FSHARP_PROJ' could not be found (are you missing a using directive or an assembly reference?)
[13:57:40][Csc] REFERENCING_FSHARPPROJ_CLASS.cs(263, 29): error CS0246: The type or namespace name 'SOME_CLASS_FROM_FSHARP_PROJ' could not be found (are you missing a using directive or an assembly reference?)
[13:57:40][Csc] REFERENCING_FSHARPPROJ_CLASS.cs(357, 50): error CS0246: The type or namespace name 'SOME_CLASS_FROM_FSHARP_PROJ' could not be found (are you missing a using directive or an assembly reference?)
[13:57:40][MSBuild] ANOTHER_PROJECT\ANOTHER_PROJECT.csproj: Build default targets
[13:57:41][MSBuild] ANOTHER2_PROJECT\ANOTHER2_PROJECT.csproj.metaproj: Build default targets
[13:57:41][ANOTHER2_PROJECT\ANOTHER2_PROJECT.csproj.metaproj] Build
[13:57:41][Build] MSBuild
[13:57:41][MSBuild] SOME_FOLDER\SOME_PARENT_REFERENCING_PROJ.csproj: Build default targets
[13:57:41][SOME_FOLDER\SOME_PARENT_REFERENCING_PROJ.csproj] Project SOME_FOLDER\SOME_PARENT_REFERENCING_PROJ.csproj failed.
[13:57:41][Step 2/3] Process exited with code 1
[13:57:41][Step 2/3] MSBuild output
[13:57:41][Step 2/3] Step 2. Build Solution (MSBuild) failed

【问题讨论】:

  • 您能否仔细检查 F# 项目正在构建到哪个目录,并交叉检查 C# 项目希望引用它的位置。我的猜测是这里的工作方式有所不同。
  • 如我所见,Fsharp 项目的 dll 没有生成(项目文件夹中没有包含 dll 的 bin 文件夹)。但是,它不会在 TeamCity 中引发任何异常。我是否需要添加某种构建顺序(先构建 Fsharp 项目,然后构建 REFERENCING_PROJECT - 尽管我认为这是默认完成的)?

标签: visual-studio build msbuild f# teamcity


【解决方案1】:

.fsproj 文件作为文本文件打开,并检查其中是否包含以下行:

  <Import Project="$(MSBuildExtensionsPath32)\FSharp\1.0\Microsoft.FSharp.Targets" Condition="!Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />
  <Import Project="$(MSBuildExtensionsPath32)\..\Microsoft F#\v4.0\Microsoft.FSharp.Targets" Condition=" Exists('$(MSBuildBinPath)\Microsoft.Build.Tasks.v4.0.dll')" />

如果没有,则在 &lt;ItemGroup&gt; 部分之前插入上面的内容,其中包含所有 .fs 文件。

仔细检查路径和文件是否确实存在于您的构建服务器上。如果没有,您可能只想将相关文件从安装了 VS 的机器上移走,尽管它们应该与 F# Tools 包一起出现。

【讨论】:

  • 不,仍然没有运气:抛出同样的错误。问题是它在构建 REFERENCING_PROJECT 时抛出错误,但在构建 FSharp_PROJECT 时没有显示错误。另外,我不完全理解 (CoreCompile target) 的含义以及为什么会在那里引发错误。
  • 嗯,问题似乎是在 F# 编译阶段没有构建任何内容。您能否将整个构建日志附加到您的问题中?
  • 我已经从 TeamCity 日志中添加了失败的部分。 FSHARP_Project bin/Debug文件夹中仍然没有生成dll。
  • 我仍然不明白为什么,在构建日志中它没有在任何地方显示 FSHARP_PROJECT 的构建条目。不应该是 FSHARP_PROJECT 的构建出现在 REFERENCING_FSHARP_PROJECT 之前的某种顺序?