wpf app.config 中的参考程序集

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17284343/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 09:04:09  来源:igfitidea点击:

Reference Assembly in app.config

c#wpfxamlapp-configgac

提问by makim

I know this Question has been asked before but not in this Context!

我知道之前已经问过这个问题,但不是在这种情况下!

I have an WPF-Application(third party) that gives me the possibility to add an XAML ResourceDictionary, so I′ve created a ClassLibrary with a Class that Implements the ICommand Interface and calls a WebService in the Execute-Method.

我有一个 WPF 应用程序(第三方),它使我可以添加 XAML ResourceDictionary,因此我创建了一个 ClassLibrary,其中包含一个实现 ICommand 接口并在 Execute-Method 中调用 WebService 的类。

Now I want to attach this Command to a Control in the Application!

现在我想将此命令附加到应用程序中的控件!

This is my ResourceDictionary:

这是我的 ResourceDictionary:

        <ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                        xmlns:iet="clr-namespace:iETSolutions.Enterprise.WorkCenter.Controls;assembly=iETSolutions.Enterprise.WorkCenter.Controls"
                        xmlns:custom="clr-namespace:Custom.Test;assembly=Custom.Test">
                 <Style TargetType="{x:Type Button}">
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Name}" Value="SearchButton">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type Button}">
                                        <Grid>
                                            <Button Command="{StaticResource cmd}" CommandParameter="{Binding ElementName=SearchTextBox, Path=Text}">
                                                <Image Source="pack://application:,,,/iETSolutions.Enterprise.WorkCenter;component/Images/PNG/iET_search.png" />
                                            </Button>
                                        </Grid>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </DataTrigger>
                    </Style.Triggers>
                 </Style>
</ResourceDictionary>

So this works like charm, if I add my Custom.Test.dll to the GAC but if I try to reference the DLL from the app.config the CommandCall fails...

所以这就像魅力一样,如果我将我的 Custom.Test.dll 添加到 GAC 但如果我尝试从 app.config 引用 DLL 命令调用失败......

Here is what I tried in the App.config to reference the Assembly:

这是我在 App.config 中尝试引用程序集的内容:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">    
      <dependentAssembly>
        <assemblyIdentity name="Custom.Test" publicKeyToken="314daa73fc3fb7cf" culture="neutral"/>
        <codeBase version="1.0.0.0" href="http://localhost/Custom/Custom.Test.dll" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Is there any possibility I can get this to Work without the need of putting my Custom DLL in the GAC?

是否有可能在不需要将我的自定义 DLL 放入 GAC 的情况下使其工作?

For the RollingOut of the Application it would be much easier to have the refernce in the App.config...

对于应用程序的推出,在 App.config 中有引用会容易得多...

采纳答案by Ivan Krivyakov

Did you try putting Custom.Test.DLL in the same directory where application executable lives?

您是否尝试将 Custom.Test.DLL 放在应用程序可执行文件所在的同一目录中?