Attribute 'TargetFrameworkAttribute' cannot be applied multiple times.

138 views
Skip to first unread message

Pranay N

unread,
Mar 24, 2025, 2:40:21 PM3/24/25
to Excel-DNA
Hello Govert, 

I'm using Visual Studio 2022 with Excel DNA 1.8.0 and I get the following error when trying to build my addin:

Attribute 'TargetFrameworkAttribute' cannot be applied multiple times.

When I click on the error message, it takes me to a file created in the Debug folder
"C:\Users..\Debug\.NETFramework,Version=v4.7.2.AssemblyAttributes.vb"

The file contains the following code:
' <autogenerated/>
            Option Strict Off
            Option Explicit On

            Imports System
            Imports System.Reflection
            <Assembly: Global.System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.7.2", FrameworkDisplayName:=".NET Framework 4.7.2")>

Govert van Drimmelen

unread,
Mar 24, 2025, 3:32:15 PM3/24/25
to exce...@googlegroups.com

Your project might have an assembly properties file that sets TargetFramework too, clashing with the generated file you show.

This would happen if your converting from an old-style project file to a new .vbproj file.

For this case, remove the extra file in your project.

 

You can also prevent the build from generating this attribute at build time with this project property

    <GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>

 

-Govert

--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/exceldna/4082c307-d52d-45a6-82ca-82a85d70e108n%40googlegroups.com.

Pranay N

unread,
Mar 24, 2025, 3:51:02 PM3/24/25
to Excel-DNA
Thank you Govert for quick response. However, I have to admit I'm lost here.  I do not have any such file setting assembly properties in my project. 

Here is my packages.config file content:
<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="ExcelDna.AddIn" version="1.8.0" targetFramework="net472" />
  <package id="ExcelDna.Integration" version="1.8.0" targetFramework="net472" />
  <package id="ExcelDna.IntelliSense" version="1.8.0" targetFramework="net472" />
  <package id="ExcelDna.Interop" version="15.0.1" targetFramework="net472" />
  <package id="ExcelDna.Registration" version="1.8.0" targetFramework="net472" />
  <package id="ExcelDna.XmlSchemas" version="1.0.0" targetFramework="net472" />
  <package id="ExcelDnaDoc" version="1.8.0" targetFramework="net472" />
  <package id="Microsoft.CSharp" version="4.7.0" targetFramework="net472" />
</packages>

And here is my MyAddin-AddIn.dna file content:
<?xml version="1.0" encoding="utf-8"?>
<DnaLibrary Name="MyAdd-In" RuntimeVersion="v4.0" xmlns="http://schemas.excel-dna.net/addin/2020/07/dnalibrary">
  <ExternalLibrary Path="MyAddin.dll" ExplicitExports="true" LoadFromBytes="true" Pack="true" IncludePdb="false" ComServer="true"/>

<Reference Path="ExcelDna.IntelliSense.dll" Pack="true" />
<Reference Path="ExcelDna.Documentation.dll" Pack="true" />

<!--
       The RuntimeVersion attribute above allows the following settings:
       * RuntimeVersion="v4.0" - for .NET Framework 4.5 or higher
       * v6.0, v7.0, v8.0 etc. for .NET

       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 https://excel-dna.net for downloads of the full distribution.
  -->
</DnaLibrary>


Govert van Drimmelen

unread,
Mar 24, 2025, 3:59:14 PM3/24/25
to exce...@googlegroups.com

In Visual Studio in the Solution Explorer, if you click the “Show All Files” button, you might see files like “AssemblyInfo.vb”.

Check whether you have a TargetFramework entry in there.

 

image001.png

Pranay N

unread,
Mar 24, 2025, 4:05:31 PM3/24/25
to Excel-DNA
There is all I have in AssemblyInfo.vb:

Imports System
Imports System.Reflection
Imports System.Runtime.InteropServices

' General Information about an assembly is controlled through the following
' set of attributes. Change these attribute values to modify the information
' associated with an assembly.

' Review the values of the assembly attributes

<Assembly: AssemblyTitle("MyAddin")>
<Assembly: AssemblyDescription("xxx")>
<Assembly: AssemblyCompany("xxx")>
<Assembly: AssemblyProduct("xxx")>
<Assembly: AssemblyCopyright("Copyright ©  2025")>
<Assembly: AssemblyTrademark("")>

<Assembly: ComVisible(False)>

'The following GUID is for the ID of the typelib if this project is exposed to COM
<Assembly: Guid("6e7ae120-a28b-44ec-bf94-0fe36b0ef14d")>

' Version information for an assembly consists of the following four values:
'
'      Major Version
'      Minor Version
'      Build Number
'      Revision
'

<Assembly: AssemblyVersion("2.6.9.0")>
<Assembly: AssemblyFileVersion("1.0.0.0")>

Govert van Drimmelen

unread,
Mar 24, 2025, 4:24:39 PM3/24/25
to exce...@googlegroups.com

When I build, I get the same file in the obj\Debug folder, but no error.

So I think you might have this attribute somewhere in a file that your project incorporates.

Maybe under the Properties folder.

 

If you can make a small project that has this problem and you can post on GitHub or somewhere, I’d be happy to have a look.

Pranay N

unread,
Mar 24, 2025, 4:42:09 PM3/24/25
to Excel-DNA
Thank you again for all the help, Govert.

I will keep trying and post the solution if and when I find it.  

A bit more background here:
I've been using your add-in for over 10 years and I have not upgraded to latest versions in recent years.  The update on my add in was using 1.6 in 2023.  I ran into several issues when attempting to upgrade to 1.8.  Therefore, I created a brand-new class library project, installed all nuget packages and moved all my code into this new file.  All the files I moved contains background program logic and should have no refences to TargetFramework.  I will have to go through them one by one to get to the bottom of the issue.  Thank you again for all your contributions to this amazing project.

Reply all
Reply to author
Forward
0 new messages