Select 客户端 ClickOnce 应用程序的目标框架

Select target framework for ClickOnce app on client-side

我们使用的是 ClickOnce 部署的 WPF 应用程序,旨在 运行 在 .Net Framework v3.5 上。该应用程序不适用于 Windows 8 或 10,如果安装了较新版本的 .Net Framework,则该应用程序无法正常工作。

我们收到错误消息:

This method explicitly uses CAS policy, which has been obsoleted by the .NET Framework. In order to enable CAS policy for compatibility reasons, please use the NetFx40_LegacySecurityPolicy configuration switch. Please see http://go.microsoft.com/fwlink/?LinkID=155570 for more information.

我无权访问源代码或编辑 Web 服务器上的 ClickOnce 文件。我需要一个可以使应用程序在我们公司的计算机上运行而无需更改 Web 服务器或代码的解决方案。

link in the error message给你答案:

Compatibility: Using the CAS Policy Legacy Option

The configuration element lets you specify that a process or library uses legacy CAS policy. When you enable this element, the policy and evidence overloads will work as they did in previous versions of the framework.

<configuration>
   <runtime>
      <NetFx40_LegacySecurityPolicy enabled="true"/>
   </runtime>
</configuration>

因此,对于 re-enable 已弃用的代码,将 <NetFx40_LegacySecurityPolicy enabled="true"/> 元素添加到 YourApp.exe.config

如果您使用的是 ClickOnce,则可以 add the setting to machine.config 代替。不建议对 machine.config 进行编辑,因为它们可能会造成 system-wide 运行 时间或安全后果,如果有其他选项可用,则不应尝试,并且永远不要未经测试。

或者,如果您想 运行 .Net 3.5 下的整个应用程序(它是带有一些额外库的 CLR 的内部版本 v2.0.50727),您可以改为指定 <supportedRuntime> 以同样的方式。这不是通过 ClickOnce 部署的应用程序的选项。

<configuration>
   <startup>
      <supportedRuntime version="v2.0.50727"/>
   </startup>
</configuration>