【问题标题】:FAKE build a project with unsafe flagFAKE 建立一个带有不安全标志的项目
【发布时间】:2014-09-10 16:09:03
【问题描述】:

我正在尝试构建一个解决方案,其中一个项目需要使用 unsafe 标志进行构建,它在项目中设置正确但是在构建时出现错误:

“不安全的代码只有在使用 /unsafe 编译时才会出现”

这是我目前的目标

    Target "CompileApp" (fun _ ->
        !! @"**\*.csproj"
          |> MSBuildRelease buildDir "Build"
          |> Log "AppBuild-Output: "
    )

我尝试添加 MsBuildParams,但不确定如何使用它们(即 MsBuildRelease 中似乎没有添加类似内容的选项

let setParams defaults =
    { defaults with
        Verbosity = Some(Quiet)
        Targets = ["Build"]
        Properties =
            [
                "AllowUnsafeBlocks", "True"
                "Configuration", "Release"
            ]
    }

这里最好的选择是为具有安全和不安全代码的项目创建两个不同的目标,还有更好的方法吗?

【问题讨论】:

    标签: f#-fake f#-fake-4


    【解决方案1】:

    我发现AllowUnsafeBlocks=true 元素仅在我的项目文件中的DEBUG|AnyCPURelease|AnyCPU PropertyGroups 下定义。

    使用它为我修复了它:

    Target "BuildApp" (fun _ ->
        !! ".\**\MyApp.*.csproj"
        |> MSBuild buildDir "Build" ["Configuration", "Release"; "Platform", "AnyCPU"]
        |> Log "AppBuild-Output: "
    )
    

    希望这会有所帮助。

    【讨论】:

    • 抱歉耽搁了,我试试这个:D
    【解决方案2】:

    好吧,我想可能是这样:

    Target "CompileUnsafe" (fun _ ->          
        let buildMode = getBuildParamOrDefault "buildMode" "Release"
        let setParams defaults =
            { defaults with
                Verbosity = Some(Quiet)
                Targets = ["Build"]
                Properties =
                    [
                        "Optimize", "True"
                        "DebugSymbols", "True"
                        "Configuration", buildMode
                        "AllowUnsafeBlocks", "True"
                    ]
            }
        build setParams "./ProjectPlugins.sln"      
    )
    

    如果有更好的解决方案,我会全力以赴(解决方案在文档中,我只是错过了)

    【讨论】:

      猜你喜欢
      • 2020-11-13
      • 1970-01-01
      • 2021-08-05
      • 2019-10-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-06
      • 1970-01-01
      相关资源
      最近更新 更多