在构建F#项目时如何为fsc创建引用?

时间:2016-03-30 13:26:44

标签: f# msbuild teamcity paket

我们有一个F#项目无法建立团队合作,无法找到解决方案。似乎在通过teamcity构建时,fsc的参数对我们来说是不正确的。如果我在同一个源上手动运行msbuild /t:Rebuild /p:Configuration=Release,那么一切正常。

我将提供失败的fsproj文件的内容以显示我的意思(它不是一个大型项目):

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <SchemaVersion>2.0</SchemaVersion>
    <ProjectGuid>3e68783b-823c-4394-85cb-4a05aa3f3722</ProjectGuid>
    <OutputType>Library</OutputType>
    <RootNamespace>SFag.DataRepository</RootNamespace>
    <AssemblyName>SFag.DataRepository</AssemblyName>
    <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
    <TargetFSharpCoreVersion>4.4.0.0</TargetFSharpCoreVersion>
    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
    <Name>Sfag.DataRepository</Name>
    <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
    <TargetFrameworkProfile />
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <Tailcalls>false</Tailcalls>
    <OutputPath>bin\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <WarningLevel>3</WarningLevel>
    <DocumentationFile>bin\Debug\SFag.DataRepository.XML</DocumentationFile>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <Tailcalls>true</Tailcalls>
    <OutputPath>bin\Release\</OutputPath>
    <DefineConstants>TRACE</DefineConstants>
    <WarningLevel>3</WarningLevel>
    <DocumentationFile>bin\Release\SFag.DataRepository.XML</DocumentationFile>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="mscorlib" />
    <Reference Include="System" />
    <Reference Include="System.Core" />
    <Reference Include="System.Numerics" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="AssemblyInfo.fs" />
    <Compile Include="Tilsynsmyndighet.fs" />
    <None Include="Script.fsx" />
    <None Include="paket.references" />
    <Compile Include="KonsesjonRepository.fs" />
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\Sfag.Contracts\Sfag.Contracts.csproj">
      <Name>Sfag.Contracts</Name>
      <Project>{260b3032-028d-417e-acde-1c332744b1bf}</Project>
      <Private>True</Private>
    </ProjectReference>
  </ItemGroup>
  <PropertyGroup>
    <MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
  </PropertyGroup>
  <Choose>
    <When Condition="'$(VisualStudioVersion)' == '11.0'">
      <PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
        <FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
      </PropertyGroup>
    </When>
    <Otherwise>
      <PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
        <FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
      </PropertyGroup>
    </Otherwise>
  </Choose>
  <Import Project="$(FSharpTargetsPath)" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
  <Choose>
    <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.6.1'">
      <ItemGroup>
        <Reference Include="FSharp.Core">
          <HintPath>..\packages\FSharp.Core\lib\net40\FSharp.Core.dll</HintPath>
          <Private>True</Private>
          <Paket>True</Paket>
        </Reference>
      </ItemGroup>
    </When>
  </Choose>
  <Choose>
    <When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.6.1'">
      <ItemGroup>
        <Reference Include="FSharp.Data.SqlClient">
          <HintPath>..\packages\FSharp.Data.SqlClient\lib\net40\FSharp.Data.SqlClient.dll</HintPath>
          <Private>True</Private>
          <Paket>True</Paket>
        </Reference>
        <Reference Include="System.Data">
          <Paket>True</Paket>
        </Reference>
        <Reference Include="System.Xml">
          <Paket>True</Paket>
        </Reference>
      </ItemGroup>
    </When>
  </Choose>
</Project>

手动运行msbuild时,我们会得到fsc.exe的正确参数:

C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0\fsc.exe -o:obj\Release\SFag.DataRepository.dll --debug:pdbonly --noframework --define:TRACE --doc:bin\Release\SFag.DataRepository.XML --optimize+ -r:E:\TeamCity\buildAgent2\work\cd80d924274f60cd\src\packages\FSharp.Core\lib\net40\FSharp.Core.dll -r:E:\TeamCity\buildAgent2\work\cd80d924274f60cd\src\packages\FSharp.Data.SqlClient\lib\net40\FSharp.Data.SqlClient.dll -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll" -r:E:\TeamCity\buildAgent2\work\cd80d924274f60cd\src\Sfag.Contracts\bin\Release\Sfag.Contracts.dll -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Core.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Numerics.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xml.dll" --target:library --warn:3 --warnaserror:76 --fullpaths --flaterrors --subsystemversion:6.00 --highentropyva+ "C:\Users\admtoja1\AppData\Local\Temp\.NETFramework,Version=v4.6.1.AssemblyAttributes.fs" AssemblyInfo.fs Tilsynsmyndighet.fs KonsesjonRepository.fs 

当teamcity运行构建时,我们无法获得完全相同的输出:

C:\Program Files (x86)\Microsoft SDKs\F#\4.0\Framework\v4.0\fsc.exe -o:obj\Release\SFag.DataRepository.dll --debug:pdbonly --noframework --define:TRACE --doc:bin\Release\SFag.DataRepository.XML --optimize+ -r:E:\TeamCity\buildAgent2\work\cd80d924274f60cd\src\packages\FSharp.Core\lib\net40\FSharp.Core.dll -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\mscorlib.dll" -r:E:\TeamCity\buildAgent2\work\cd80d924274f60cd\src\Sfag.Contracts\bin\Release\Sfag.Contracts.dll -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Core.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Data.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Numerics.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.6.1\System.Xml.dll" --target:library --warn:3 --warnaserror:76 --fullpaths --flaterrors --subsystemversion:6.00 --highentropyva+ "E:\TeamCity\buildAgent2\temp\buildTmp\.NETFramework,Version=v4.6.1.AssemblyAttributes.fs" AssemblyInfo.fs Tilsynsmyndighet.fs KonsesjonRepository.fs 

错误是Teamcity版本中没有FSharp.Data.SqlClient的引用。这真的很奇怪,因为我认为teamcity只会在我的解决方案上调用msbuild

2 个答案:

答案 0 :(得分:0)

FSharp.Data.Client来自NuGet包,我猜想在编译步骤之前NuGet包没有正确恢复。

通过管理链接

在TeamCity上启用NuGet

enter image description here

在编译步骤之前添加NuGet安装步骤

enter image description here

希望这有帮助

答案 1 :(得分:0)

这可能是一个新手的错误。由于我们希望在Visual Studio中构建时自动解析包,因此我们必须在项目文件中添加一行:

$("#dialog").load('Popup.html', function() {
    $(this).dialog("open");
    ko.applyBindings({someText: "value from knockout"}, $("#container")[0]);
})

此文件位于项目文件中的正确位置也很重要。如果我在上面

<Import Project="..\.paket\paket.targets" />

它没有用。所以我把它放在下面,现在一切都像魅力一样。