feO2x
feO2x

Reputation: 5718

Multi-target with .NET Compact Framework 3.5 using new .csproj format?

Is there a way to target .NET Compact Framework 3.5 with the new .csproj file format? I want to be able to target the following frameworks:

<TargetFrameworks>netstandard2.0;netstandard1.0;net45;net40;net35;net35-cf</TargetFrameworks>

What I've done so far is based on this GitHub gist - in detail, I've done the following:

  1. Installed .NET CF 3.5 and Power Toys
  2. Replaced $(MSBuildBinPath) with C:\Windows\Microsoft.NET\Framework\v3.5 in file C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.CSharp.targets
  3. Copied all files from
    • C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE to
    • C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework
  4. Created file RedistList\FrameworkList.xml in the above folder with the following contents:

    <?xml version="1.0" encoding="utf-8"?> <FileList Redist="Net35-CF" Name=".NET Compact Framework 3.5"> </FileList>

  5. Added registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v3.5,Profile=CompactFramework (just key, no value)

  6. Created new project, set TargetFrameworks and added conditional property groups for net35-cf:
<PropertyGroup Condition="'$(TargetFramework)' == 'net35-cf'">
    <!-- inference fails for this TFM, so specify it by hand -->
    <TargetFrameworkIdentifier>.NETFramework</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
    <TargetFrameworkProfile>CompactFramework</TargetFrameworkProfile>
    <!-- define compilation constants by hand too -->
    <DefineConstants>NET35_CF;WindowsCE</DefineConstants>
    <!-- disable implicit references, these are specified by hand, below -->
    <DisableImplicitFrameworkReferences>True</DisableImplicitFrameworkReferences>
</PropertyGroup>
<PropertyGroup Condition=" '$(TargetFramework)' == 'net35-cf' ">
    <NoStdLib>True</NoStdLib>
    <NoConfig>true</NoConfig>
    <FileAlignment>512</FileAlignment>
    <GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
    <PlatformID>E2BECB1F-8C8C-41ba-B736-9BE7D946A398</PlatformID>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net35-cf' ">
    <Reference Include="mscorlib, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
    <Reference Include="System, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
    <Reference Include="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=969db8053d3322ac" />
</ItemGroup>

However, when I try to compile my code, I get the following error message:

net35-cf error with new csproj

It seems that the general compilation is working, but the AssemblyFileVersionAttributeis not part of the compact framework?

Update 1: when the net35-cf TFM is removed, the project compiles just fine.

Thanks for your help in advance!

Upvotes: 1

Views: 1605

Answers (1)

NightOwl888
NightOwl888

Reputation: 56849

You can disable generation of AssemblyFileVersionAttribute and AssemblyVersionAttribute by specifying so in the .csproj file.

<PropertyGroup "'$(TargetFramework)' == 'net35-cf'">
    <GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
    <GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
</PropertyGroup>

Reference: Equivalent to AssemblyInfo in dotnet core/csproj

Upvotes: 1

Related Questions