简体   繁体   中英

How to make F# projects which will work same on VS2010 / VS2013-preview?

New F# projects comes with

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

msbuild just fails with it so I even can't write an build script based on this project file.

My solution:

<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\FSharp\Microsoft.FSharp.Targets" />

I set v12.0 instead of $(VisualStudioVersion) because VisualStudioVersion is 11 for my msbuild. So but this breaks compatibility with other Visual Studio versions.

I guess I need to make something alike

<FSharpTargetsPath Condition="'$(VisualStudioVersion)' == '11.0'">$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>

and

<FSharpTargetsPath Condition="'$(VisualStudioVersion)' == '12.0'">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>

But that even doesn't look alike good solution. Is there proper way?

Also I have problems with running 3.0 F# compiler fsc.exe and software alike FAKE :

Could not load file or assembly FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies

So how to not break compatibility between 3.0 / msbuild and 3.1 and newer VS2013-preview stuff ?

The more specific answer that I guess Danny should have given is:

  <Choose>
    <When Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#')">
      <PropertyGroup>
        <FSharpSdkPathPrefix>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#</FSharpSdkPathPrefix>
      </PropertyGroup>
    </When>
    <Otherwise>
      <Choose>
        <When Condition="Exists('$(MSBuildExtensionsPath32)\..\..\..\..\Microsoft SDKs\F#')">
          <PropertyGroup>
            <FSharpSdkPathPrefix>$(MSBuildExtensionsPath32)\..\..\..\..\Microsoft SDKs\F#</FSharpSdkPathPrefix>
          </PropertyGroup>
        </When>
        <Otherwise>
          <PropertyGroup>
            <FSharpSdkPathPrefix></FSharpSdkPathPrefix>
          </PropertyGroup>
        </Otherwise>
      </Choose>
    </Otherwise>
  </Choose>
  <PropertyGroup>
    <FSharpSdkPathSuffix>Framework\v4.0\Microsoft.FSharp.Targets</FSharpSdkPathSuffix>
  </PropertyGroup>
  <Choose>
    <When Condition="'$(FSharpSdkPathPrefix)' == ''">
      <PropertyGroup>
        <FSharpTargetsPath></FSharpTargetsPath>
      </PropertyGroup>
    </When>
    <Otherwise>
      <Choose>
        <When Condition="Exists('$(FSharpSdkPathPrefix)\4.0\$(FSharpSdkPathSuffix)')">
          <PropertyGroup>
            <FSharpTargetsPath>$(FSharpSdkPathPrefix)\4.0\$(FSharpSdkPathSuffix)</FSharpTargetsPath>
          </PropertyGroup>
        </When>
        <Otherwise>
          <Choose>
            <When Condition="Exists('$(FSharpSdkPathPrefix)\3.1\$(FSharpSdkPathSuffix)')">
              <PropertyGroup>
                <FSharpTargetsPath>$(FSharpSdkPathPrefix)\3.1\$(FSharpSdkPathSuffix)</FSharpTargetsPath>
              </PropertyGroup>
            </When>
            <Otherwise>
              <Choose>
                <When Condition="Exists('$(FSharpSdkPathPrefix)\3.0\$(FSharpSdkPathSuffix)')">
                  <PropertyGroup>
                    <FSharpTargetsPath>$(FSharpSdkPathPrefix)\3.0\$(FSharpSdkPathSuffix)</FSharpTargetsPath>
                  </PropertyGroup>
                </When>
                <Otherwise>
                  <PropertyGroup>
                    <FSharpTargetsPath></FSharpTargetsPath>
                  </PropertyGroup>
                </Otherwise>
              </Choose>
            </Otherwise>
          </Choose>
        </Otherwise>
      </Choose>
    </Otherwise>
  </Choose>
  <Import Condition="'$(FSharpTargetsPath)' != ''" Project="$(FSharpTargetsPath)" />
  <Target Name="BeforeBuild">
    <Message Condition="'$(FSharpTargetsPath)' == ''" Importance="High" Text="F# SDK path was not found!" />
  </Target>

This should work with all versions.

I would start by creating projects in both versions and diffing the project files. If you build a project file that contains the superset of both files, with appropriate Condition attributes so that each version of VS reads the correct parts, in theory it should work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM