编译 Castle.ActiveRecord 以允许部分信任?

发布于 2024-10-01 06:25:46 字数 1837 浏览 7 评论 0原文

如何构建 Castle.Core、Castle.ActiveRecord 和 NHibernate 以允许部分信任?网络上有大量资源展示了如何做到这一点,但是我发现的每个网站都说使用 nant build -D: assembly.allow-partially-trusted-callers=true 来构建每个程序集。当我查看 Castle.Core trunk 时,没有 *.build 文件。

如何才能做到这一点?我正在使用 .NET 3.5 。这不是网络应用程序。

编辑:我们正在使用 NHibernate 2.1.2GA(我相信是最新的稳定版本)。下面给出的说明的问题在于,它们看起来像是从主干构建 Castle.Core 和 Castle.ActiveRecord 。 Trunk 似乎需要 NHibernate 3.0.0,这与我们的版本不匹配。

解决方案

我几乎所有的调整都是在项目属性下的“安全”选项卡中完成的。

  • 在“您的应用程序将从以下位置安装的区域:”标签下,我选择了“(自定义)”
  • 至于应用程序所需的权限,我必须包括 SqlClientPermission 和 UIPermission。为了消除未来开发的问题,我选择了“授予程序集不受限制地访问 x”,其中是所选权限。这是针对上面显示的两个权限完成的。请注意,您选择包含的权限将基于每个应用程序,并且没有两种情况是相同的。
  • 在“高级...”按钮下,我取消选择了两个选项(“使用所选权限集调试此应用程序”和“授予应用程序对其原始站点的访问权限”)。

另外,由于应用程序和 SQL Server 驻留在不同的域下,我必须设置连接字符串以包含数据库服务器域。所以我原来的连接字符串数据源必须从“Data Source=DB_SERVER”到“Data Source=DB_SERVER.DOMAIN”。

最后,我必须在所有配置部分设置 requirePermission="false"。我的 configSections 最终是这样的:

  <configSections>
    <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" requirePermission="false"/>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" requirePermission="false"/>
    <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    <section name="hibernate-configuration" requirePermission="false" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
  </configSections>

在一切都说完并完成之后,我成功地能够在来自不同域的文件共享上发布此应用程序,并让用户毫无问题地安装该应用程序。将这些步骤应用到我们的其他应用程序并使用我们新编译的程序集也非常有效。

How can I build Castle.Core, Castle.ActiveRecord and NHibernate to allow partial trust? There are plenty of resources on the web showing how this can be done, however every site I found says to use nant build -D:assembly.allow-partially-trusted-callers=true to build each assembly. When I look at the Castle.Core trunk here there is no *.build file.

How can this be accomplished? I am using .NET 3.5 . This is not a web application.

Edit: We're using NHibernate 2.1.2GA (latest stable version, I believe). The problem with the instructions given below is that it looks like their referring to building Castle.Core and Castle.ActiveRecord from trunk. Trunk appears to be requiring NHibernate 3.0.0 which doesn't match our version.

Solution

Almost all of my tweaks were done in the Security tab under project properties.

  • Under the "Zone your application will be installed from:" label I selected "(Custom)"
  • As for the permissions required by the application, I had to include SqlClientPermission as well as UIPermission. In order to negate problems for future development I selected "Grant assemblies unrestricted access to x" where is the selected permission. That was done for both permissions shown above. Note that the permissions you select to include will be on a per application basis and no two cases will be the same.
  • Under the "Advanced..." button I unselected both options ("Debug this application with the selected permission set" and "Grant the application access to its site of origin").

Also, since the application and SQL Server are residing under different domains I had to set my connection string to include the database server domain. So my original connection string data source had to go from "Data Source=DB_SERVER" to "Data Source=DB_SERVER.DOMAIN".

Lastly, I had to set requirePermission="false" on all of my configuration sections. My configSections ended up like this:

  <configSections>
    <section name="activerecord" type="Castle.ActiveRecord.Framework.Config.ActiveRecordSectionHandler, Castle.ActiveRecord" requirePermission="false"/>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" requirePermission="false"/>
    <section name="nhibernate" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    <section name="hibernate-configuration" requirePermission="false" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
  </configSections>

After everything was said and done I was successfully able to publish this application on a file share from a different domain and have the users install the application with no issues. Applying these steps to our other applications and using our newly compiled assemblies also worked like a charm.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪落纷纷 2024-10-08 06:25:46

您将需要 MSBuild 4.0,nant 构建脚本早已不复存在。

如果您有 Visual Studio 2010,请打开 Visual Studio 2010 命令提示符,否则请确保使用 .NET 4.0 框架中的 MSBuild。

假设您已经为 APTCA 构建了 NHibernate(nant -D:-D: assembly.allow-partially-trusted-callers=true 可以工作)

  • cd Core

  • MSBuild buildscripts\build。项目 /p:AllowPartiallyTrustedCallers=true
    /p:Configuration=NET35-Release

  • 将 Castle.Core.dll 从构建文件夹复制到 ActiveRecord\lib\net35

  • cd ActiveRecord

  • MSBuild buildscripts\build.proj
    /p:AllowPartiallyTrustedCallers=true /p:Configuration=发布
    /p:FrameworkVersion=v3.5 /p:BuildConfigKey=NET35

You'll need MSBuild 4.0, the nant build scripts have since long gone.

If you've got Visual Studio 2010, open the Visual Studio 2010 Command Prompt otherwise make sure you use MSBuild from the .NET 4.0 framework.

Given you've got NHibernate built for APTCA (nant -D:-D:assembly.allow-partially-trusted-callers=true works thre)

  • cd Core

  • MSBuild buildscripts\build.proj /p:AllowPartiallyTrustedCallers=true
    /p:Configuration=NET35-Release

  • Copy Castle.Core.dll from the build folder to ActiveRecord\lib\net35

  • cd ActiveRecord

  • MSBuild buildscripts\build.proj
    /p:AllowPartiallyTrustedCallers=true /p:Configuration=Release
    /p:FrameworkVersion=v3.5 /p:BuildConfigKey=NET35

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文