Excel-DNA / ExcelDna

Excel-DNA - Free and easy .NET for Excel. This repository contains the core Excel-DNA library.
https://excel-dna.net
zlib License
1.29k stars 274 forks source link

F# complie xll failed. #354

Closed LastsForever closed 8 months ago

LastsForever commented 3 years ago

I used Rider to create a .Net Framework Class Library, and tried to compile the xll file but failed. Here is the log file: ` 生成启动时间为 2020/11/15 12:32:33。 日志记录详细程度设置为: Normal。 1>项目“C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\UDFs.fsproj”在节点 1 上(build 个目标)。 1>GenerateTargetFrameworkMonikerAttribute: 正在跳过目标“GenerateTargetFrameworkMonikerAttribute”,因为所有输出文件相对于输入文件而言都是最新的。 CoreCompile: C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\packages\FSharp.Compiler.Tools.10.0.2\build..\tools\fsc.exe -o:obj\Debug\UDFs.dll -g --debug:portable --noframework --define:DEBUG --define:TRACE --optimize- --tailcalls- -r:C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\packages\ExcelDna.Integration.1.1.0\lib\ExcelDna.Integration.dll -r:C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\packages\FSharp.Core.4.5.2\lib\net45\FSharp.Core.dll -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\mscorlib.dll -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Core.dll -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.dll -r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5\System.Numerics.dll --target:library --warn:3 --warnaserror:76 --fullpaths --flaterrors --subsystemversion:6.00 --highentropyva+ --warnon:1182 AssemblyInfo.fs Library.fs obj\Debug.NETFramework,Version=v4.5.AssemblyAttributes.fs

 1>C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\Library.fs(7,9): warning FS1182: The value 'add' is unused
   _CopyFilesMarkedCopyLocal:
     正在对“C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\obj\Debug\UDFs.fsproj.CopyComplete”执行 Touch 任务。
   CopyFilesToOutputDirectory:
     正在将文件从“C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\obj\Debug\UDFs.dll”复制到“C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\bin\Debug\UDFs.dll”。
     UDFs -> C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\bin\Debug\UDFs.dll
     正在将文件从“C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\obj\Debug\UDFs.pdb”复制到“C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\bin\Debug\UDFs.pdb”。
   ExcelDnaBuild:
     ---
     ExcelDnaBuild: Running CreateExcelAddIn MSBuild Task
     ExcelDnaBuild: ----Arguments----
     ExcelDnaBuild: FilesInProject: 3
     ExcelDnaBuild:   ExcelDna-Template.dna
     ExcelDnaBuild:   packages.config
     ExcelDnaBuild:   Properties\ExcelDna.Build.props
     ExcelDnaBuild: OutDirectory: bin\Debug\
     ExcelDnaBuild: Xll32FilePath: C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\packages\ExcelDna.AddIn.1.1.1\build\..\tools\ExcelDna.xll
     ExcelDnaBuild: Xll64FilePath: C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\packages\ExcelDna.AddIn.1.1.1\build\..\tools\ExcelDna64.xll
     ExcelDnaBuild: Create32BitAddIn: True
     ExcelDnaBuild: Create64BitAddIn: True
     ExcelDnaBuild: FileSuffix32Bit: 
     ExcelDnaBuild: FileSuffix64Bit: 64
     ExcelDnaBuild: -----------------
     ExcelDnaBuild: Number of files in project: 3
     ExcelDnaBuild: ExcelDna-Template.dna -> bin\Debug\ExcelDna-Template.dna
     ExcelDnaBuild: packages\ExcelDna.AddIn.1.1.1\build\..\tools\ExcelDna.xll -> bin\Debug\ExcelDna-Template.xll
     ExcelDnaBuild: ---
     ExcelDnaBuild: ExcelDna-Template.dna -> bin\Debug\ExcelDna-Template64.dna
     ExcelDnaBuild: packages\ExcelDna.AddIn.1.1.1\build\..\tools\ExcelDna64.xll -> bin\Debug\ExcelDna-Template64.xll
     ---
   ExcelDnaPack:
     ExcelDnaPack: bin\Debug\ExcelDna-Template.dna -> bin\Debug\ExcelDna-Template-packed.xll
     "C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\packages\ExcelDna.AddIn.1.1.1\build\..\tools\ExcelDnaPack.exe" "bin\Debug\ExcelDna-Template.dna" /Y  /O "bin\Debug\ExcelDna-Template-packed.xll"
     Using base add-in bin\Debug\ExcelDna-Template.xll
     !!! ExternalLibrary `%OutputFileName%` not found. Aborting.
 1>C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\packages\ExcelDna.AddIn.1.1.1\build\ExcelDna.AddIn.targets(196,5): error MSB3073: 命令“"C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\packages\ExcelDna.AddIn.1.1.1\build\..\tools\ExcelDnaPack.exe" "bin\Debug\ExcelDna-Template.dna" /Y  /O "bin\Debug\ExcelDna-Template-packed.xll"”已退出,代码为 1。
 1>已完成生成项目“C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\UDFs.fsproj”(build 个目标)的操作 - 失败。

生成失败。

   “C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\UDFs.fsproj”(build 目标) (1) ->
   (CoreCompile 目标) -> 
     C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\Library.fs(7,9): warning FS1182: The value 'add' is unused

   “C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\UDFs.fsproj”(build 目标) (1) ->
   (ExcelDnaPack 目标) -> 
     C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\packages\ExcelDna.AddIn.1.1.1\build\ExcelDna.AddIn.targets(196,5): error MSB3073: 命令“"C:\Users\Victor\Documents\scripts\fsharp\ExcelAddIn\UDFs\packages\ExcelDna.AddIn.1.1.1\build\..\tools\ExcelDnaPack.exe" "bin\Debug\ExcelDna-Template.dna" /Y  /O "bin\Debug\ExcelDna-Template-packed.xll"”已退出,代码为 1。

1 个警告
1 个错误

已用时间 00:00:04.10

`

govert commented 3 years ago

I don't know Rider or Chinese, so it's really hard for me to support. One problem is that Rider does not install the NuGet package correctly. You can try to fix this by:

LastsForever commented 3 years ago

Thank you! It works well with it. But I still wondering 1) if there is a way to edit some config file to build the xll file automaticly in Rider. 2) if it can be done in Visual Studio. It seems that there's no default way to create a .net framework class library with F#.

LastsForever commented 3 years ago

Finally I found that the project builded without error, but the xll file didn't work. Maybe there's still something wrong with Rider.

The content of the file UDF.dna is:

<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="%ProjectName% Add-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2018/05/dnalibrary">
  <ExternalLibrary Path="UDFs.dll" ExplicitExports="false" LoadFromBytes="true" Pack="true" IncludePdb="false" />

  <!--
       The RuntimeVersion attribute above allows two settings:
       * RuntimeVersion="v4.0" - for .NET 4 and 4.5
       * RuntimeVersion="v2.0" - for .NET 2.0, 3.0 and 3.5

       You can have IntelliSense (autocomplete) and validation for this file.
       See https://github.com/Excel-DNA/ExcelDna/tree/master/Distribution/XmlSchemas/

       Additional referenced assemblies can be specified by adding 'Reference' tags. 
       These libraries will not be examined and registered with Excel as add-in libraries, 
       but will be packed into the -packed.xll file and loaded at runtime as needed.
       For example:

       <Reference Path="Another.Library.dll" Pack="true" />

       Excel-DNA also allows the XML for ribbon UI extensions to be specified in the .dna file.
       See the main Excel-DNA site at http://excel-dna.net for downloads of the full distribution.
  -->
</DnaLibrary>

The content of the file Library.fs is:

namespace UDFs
open System
open ExcelDna.Integration

type Class() = 
    [<ExcelFunction(Category="FSharp Functions", Description="FSharp function to add numbers")>]
    let add x y = x + y
govert commented 3 years ago

It looks like the <DnaLibrary Name="%...." /> should also be fixed.

Then the function must be static for it to be recognized by Excel-DNA. Top-level code in a module would also work.

Try this as your F# source file:

module MyFunctions

open ExcelDna.Integration

[<ExcelFunction(Description="My first .NET function")>]
let HelloDna name =
    "Hello " + name
LastsForever commented 3 years ago

It looks like the <DnaLibrary Name="%...." /> should also be fixed.

Then the function must be static for it to be recognized by Excel-DNA. Top-level code in a module would also work.

Try this as your F# source file:

module MyFunctions

open ExcelDna.Integration

[<ExcelFunction(Description="My first .NET function")>]
let HelloDna name =
    "Hello " + name

Cool!!!