-1

I've got a class library created with VS2015, and now I have to add multitarget support.

Since the new VS2017 .csproj format handles it in a pretty neat way, I've decided to migrate to the new format. So now my .csproj looks like this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net452;net46</TargetFrameworks>
    <Description>My description</Description>
    <Authors>me</Authors>
    <Copyright>Copyright ©  2017</Copyright>
    <AssemblyVersion>1.0.1.1</AssemblyVersion>
    <AssemblyFileVersion>1.0.1.1</AssemblyFileVersion>
    <Configurations>Debug;Release</Configurations>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <DefineConstants>DEBUG;TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
    <DebugType>pdbonly</DebugType>
    <Optimize>true</Optimize>
    <DefineConstants>TRACE</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
  </PropertyGroup>
  <PropertyGroup>
    <RunPostBuildEvent>OnBuildSuccess</RunPostBuildEvent>
    <Version>1.0.1.1</Version>
    <GeneratePackageOnBuild>false</GeneratePackageOnBuild>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="AutoMapper" Version="4.2.1" />
  </ItemGroup>
</Project>

Checking the bin folders, I can notice that the dlls for both targets match in size, (which didn't happen when I compiled with the old csproj format), so I was wondering if both files have the same content.

Is there a way to check it?

Thanks in advance!

lerp90
  • 503
  • 8
  • 23
  • 1
    Well the simplest way to check for file equality is to use a sha-256 hash or something similar. There are lots of command-line tools to hash files. – Jon Skeet Mar 28 '18 at 13:07
  • To see the actual differences there are tools such as [JustAssembly](https://www.telerik.com/justassembly) – Crowcoder Mar 28 '18 at 13:08
  • Hi @Crowcoder! Thanks for the advice! I've tried it and the code seems to be the same on the assemblies built from both the old and the new csproj, but file sizes are different. – lerp90 Mar 28 '18 at 14:20
  • @lerp90 The C# compiler does insert at least a few different items, such as `TargetFrameworkAttribute`. That should lead to a tiny difference in file size. Generally speaking, multitargeting `net452` and `net46` is meaningless. – Lex Li Mar 28 '18 at 19:01

1 Answers1

0

Compiling in release with new .csproj generates different .dll comparing to old .csproj

As you can see, the new .csproj format has become a lot smaller out-of-the-box and it is much more readable as well. Most of the magic is happening through the Sdk attribute on the Project element. So we call these new projects SDK-based projects.

When we build from the old .csproj format project, all content in AssemblyInfo.cs file will insert into the dll, but when you build from the new .csproj format, the new .csproj generate their own AssemblyInfo.cs. However, InternalsVisibleToAttribute, CLSCompliantAttribute and others that are not automatically generated. That was the Lex said, "The C# compiler does insert at least a few different items, such as TargetFrameworkAttribute". So it is not same as AssemblyInfo.cs. Thus, this should lead to small differences in file size.

Besides, when you check the dll with other tools, most of those tools check the methods and classes in the dll, not those attributes, that is the reason why the code seems to be the same on the assemblies built from both the old and the new csproj, but file sizes are different.

Hope this helps.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135