使用新的 .csproj 格式的 .NET Compact Framework 3.5 的多目标?
Multi-target with .NET Compact Framework 3.5 using new .csproj format?
有没有办法使用新的 .csproj
文件格式来定位 .NET Compact Framework 3.5?我希望能够针对以下框架:
<TargetFrameworks>netstandard2.0;netstandard1.0;net45;net40;net35;net35-cf</TargetFrameworks>
到目前为止我所做的都是基于此 GitHub gist - 详细地说,我做了以下内容:
- 已安装 .NET CF 3.5 和 Power Toys
- 已将文件
C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.CSharp.targets
中的 $(MSBuildBinPath)
替换为 C:\Windows\Microsoft.NET\Framework\v3.5
- 复制了来自
C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE
至
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework
在上述文件夹中创建了文件 RedistList\FrameworkList.xml
,内容如下:
<?xml version="1.0" encoding="utf-8"?>
<FileList Redist="Net35-CF" Name=".NET Compact Framework 3.5">
</FileList>
已添加注册表项 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v3.5,Profile=CompactFramework
(只有键,没有值)
- 创建了新项目,设置
TargetFrameworks
并为 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>
但是,当我尝试编译代码时,收到以下错误消息:
一般编译好像可以,但是AssemblyFileVersionAttribute
不是紧凑框架的一部分?
更新 1:删除 net35-cf
TFM 后,项目编译正常。
提前感谢您的帮助!
您可以通过在 .csproj
文件中指定来禁用 AssemblyFileVersionAttribute
和 AssemblyVersionAttribute
的生成。
<PropertyGroup "'$(TargetFramework)' == 'net35-cf'">
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
</PropertyGroup>
参考:
有没有办法使用新的 .csproj
文件格式来定位 .NET Compact Framework 3.5?我希望能够针对以下框架:
<TargetFrameworks>netstandard2.0;netstandard1.0;net45;net40;net35;net35-cf</TargetFrameworks>
到目前为止我所做的都是基于此 GitHub gist - 详细地说,我做了以下内容:
- 已安装 .NET CF 3.5 和 Power Toys
- 已将文件
C:\Windows\Microsoft.NET\Framework\v3.5\Microsoft.CompactFramework.CSharp.targets
中的$(MSBuildBinPath)
替换为C:\Windows\Microsoft.NET\Framework\v3.5
- 复制了来自
C:\Program Files (x86)\Microsoft.NET\SDK\CompactFramework\v3.5\WindowsCE
至C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v3.5\Profile\CompactFramework
在上述文件夹中创建了文件
RedistList\FrameworkList.xml
,内容如下:<?xml version="1.0" encoding="utf-8"?> <FileList Redist="Net35-CF" Name=".NET Compact Framework 3.5"> </FileList>
已添加注册表项
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\.NETFramework,Version=v3.5,Profile=CompactFramework
(只有键,没有值)- 创建了新项目,设置
TargetFrameworks
并为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>
但是,当我尝试编译代码时,收到以下错误消息:
一般编译好像可以,但是AssemblyFileVersionAttribute
不是紧凑框架的一部分?
更新 1:删除 net35-cf
TFM 后,项目编译正常。
提前感谢您的帮助!
您可以通过在 .csproj
文件中指定来禁用 AssemblyFileVersionAttribute
和 AssemblyVersionAttribute
的生成。
<PropertyGroup "'$(TargetFramework)' == 'net35-cf'">
<GenerateAssemblyFileVersionAttribute>false</GenerateAssemblyFileVersionAttribute>
<GenerateAssemblyVersionAttribute>false</GenerateAssemblyVersionAttribute>
</PropertyGroup>
参考: