Fix dependency references issue of c# plugins.

This commit is contained in:
qianlifeng
2014-02-23 13:32:28 +08:00
parent 67fd2b4ac0
commit 2ade16a87a
12 changed files with 210 additions and 44 deletions

View File

@@ -23,53 +23,36 @@ namespace Wox.Plugin.Doc
List<Result> results = new List<Result>();
if (query.ActionParameters.Count == 0)
{
results.Add(new Result()
{
Title = "Current supported docs:"
});
results.AddRange(docs.Select(o => new Result()
{
Title = o.Name.Replace(".docset", ""),
Title = o.Name.Replace(".docset", "").Replace(" ",""),
IcoPath = o.IconPath
}).ToList());
return results;
}
if (query.ActionParameters.Count >= 2)
{
Doc firstOrDefault = docs.FirstOrDefault(o => o.Name.Replace(".docset", "").Replace(" ","").ToLower() == query.ActionParameters[0]);
if (firstOrDefault != null)
{
results.AddRange(QuerySqllite(firstOrDefault, query.ActionParameters[1]));
}
}
else
{
foreach (Doc doc in docs)
{
results.AddRange(QuerySqllite(doc, query.ActionParameters[0]));
}
}
return results;
}
public void Init(PluginInitContext context)
{
//todo:move to common place
var otherCompanyDlls = new DirectoryInfo(context.PluginMetadata.PluginDirecotry).GetFiles("*.dll");
AppDomain.CurrentDomain.AssemblyResolve += (sender, args) =>
{
var dll = otherCompanyDlls.FirstOrDefault(fi =>
{
try
{
Assembly assembly = Assembly.LoadFile(fi.FullName);
return assembly.FullName == args.Name;
}
catch
{
return false;
}
});
if (dll == null)
{
return null;
}
return Assembly.LoadFile(dll.FullName);
};
docsetBasePath = context.PluginMetadata.PluginDirecotry + @"Docset";
if (!Directory.Exists(docsetBasePath))
Directory.CreateDirectory(docsetBasePath);
@@ -110,7 +93,6 @@ namespace Wox.Plugin.Doc
}
}
}
}
return imagePath;
}

View File

@@ -0,0 +1,5 @@
How to use?
1. Docset download link:[http://kapeli.com/docset_links](http://kapeli.com/docset_links)
2. Unzip doc zip into "Plugins\Doc\Docset\{docname}"
3. Restart Wox

View File

@@ -83,6 +83,7 @@
<None Include="plugin.ini">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Include="README.md" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
@@ -101,7 +102,7 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy /Y /E $(TargetDir)*.* $(SolutionDir)Wox\bin\Debug\Plugins\Doc\</PostBuildEvent>
<PostBuildEvent>xcopy /Y /E $(TargetDir)*.* $(SolutionDir)Wox\bin\Debug\Plugins\$(ProjectName)\</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
namespace Wox.Plugin.DotnetPluginTest
{
public class Main : IPlugin
{
public List<Result> Query(Query query)
{
return new List<Result>();
}
public void Init(PluginInitContext context)
{
var s = JsonSerializer.Create();
}
}
}

View File

@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// 有关程序集的常规信息通过以下
// 特性集控制。更改这些特性值可修改
// 与程序集关联的信息。
[assembly: AssemblyTitle("Wox.Plugin.DotnetPluginTest")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Wox.Plugin.DotnetPluginTest")]
[assembly: AssemblyCopyright("Copyright © 2014")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// 将 ComVisible 设置为 false 使此程序集中的类型
// 对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型,
// 则将该类型上的 ComVisible 特性设置为 true。
[assembly: ComVisible(false)]
// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
[assembly: Guid("62685493-1710-4c1d-a179-cf466a44f45e")]
// 程序集的版本信息由下面四个值组成:
//
// 主版本
// 次版本
// 生成号
// 修订号
//
// 可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

View File

@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Wox.Plugin.DotnetPluginTest</RootNamespace>
<AssemblyName>Wox.Plugin.DotnetPluginTest</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\..\packages\Newtonsoft.Json.6.0.1\lib\net35\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Main.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Wox.Plugin\Wox.Plugin.csproj">
<Project>{8451ecdd-2ea4-4966-bb0a-7bbc40138e80}</Project>
<Name>Wox.Plugin</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
<None Include="plugin.ini">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy /Y /E $(TargetDir)*.* $(SolutionDir)Wox\bin\Debug\Plugins\$(ProjectName)\</PostBuildEvent>
</PropertyGroup>
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。启用“NuGet 程序包还原”可下载这些程序包。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
</Target>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="6.0.1" targetFramework="net35" />
</packages>

View File

@@ -0,0 +1,8 @@
[plugin]
ActionKeyword = ts
Name = dotnet test
Author = qianlifeng
Version = 0.1
Language = csharp
Description = test
ExecuteFile = Wox.Plugin.DotnetPluginTest.dll

View File

@@ -16,7 +16,7 @@
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\Wox\bin\Debug\Plugins\Everything\</OutputPath>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
@@ -81,10 +81,9 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy /Y $(TargetDir)$(TargetFileName) $(SolutionDir)Wox\bin\Debug\Plugins\Everything\
xcopy /Y $(TargetDir)plugin.ini $(SolutionDir)Wox\bin\Debug\Plugins\Everything\
xcopy /Y $(ProjectDir)x86\Everything.dll $(SolutionDir)Wox\bin\Debug\Plugins\Everything\x86\
xcopy /Y $(ProjectDir)x64\Everything.dll $(SolutionDir)Wox\bin\Debug\Plugins\Everything\x64\</PostBuildEvent>
<PostBuildEvent>xcopy /Y /E $(TargetDir)*.* $(SolutionDir)Wox\bin\Debug\Plugins\$(ProjectName)\
xcopy /Y $(ProjectDir)x86\Everything.dll $(SolutionDir)Wox\bin\Debug\Plugins\$(ProjectName)\x86\
xcopy /Y $(ProjectDir)x64\Everything.dll $(SolutionDir)Wox\bin\Debug\Plugins\$(ProjectName)\x64\</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

View File

@@ -69,9 +69,7 @@
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<PropertyGroup>
<PostBuildEvent>xcopy /Y $(TargetDir)$(TargetFileName) $(SolutionDir)Wox\bin\Debug\Plugins\Fanyi\
xcopy /Y $(TargetDir)plugin.ini $(SolutionDir)Wox\bin\Debug\Plugins\Fanyi\
xcopy /Y $(ProjectDir)Images\*.* $(SolutionDir)Wox\bin\Debug\Plugins\Fanyi\Images\</PostBuildEvent>
<PostBuildEvent>xcopy /Y /E $(TargetDir)*.* $(SolutionDir)Wox\bin\Debug\Plugins\$(ProjectName)\</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.

33
Wox.sln
View File

@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.21005.1
VisualStudioVersion = 12.0.30110.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Test", "Wox.Test\Wox.Test.csproj", "{FF742965-9A80-41A5-B042-D6C7D3A21708}"
EndProject
@@ -25,6 +25,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.Everything", "Pl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.UAC", "Wox.UAC\Wox.UAC.csproj", "{C9BC17A0-C2BC-4185-AC1F-32E3352C1233}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Wox.Plugin.DotnetPluginTest", "Plugins\Wox.Plugin.DotnetPluginTest\Wox.Plugin.DotnetPluginTest.csproj", "{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -346,6 +348,34 @@ Global
{C9BC17A0-C2BC-4185-AC1F-32E3352C1233}.UnitTests|Win32.ActiveCfg = Release|Any CPU
{C9BC17A0-C2BC-4185-AC1F-32E3352C1233}.UnitTests|x64.ActiveCfg = Release|Any CPU
{C9BC17A0-C2BC-4185-AC1F-32E3352C1233}.UnitTests|x86.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Debug|Win32.ActiveCfg = Debug|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Debug|x64.ActiveCfg = Debug|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Debug|x86.ActiveCfg = Debug|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.EmbeddingTest|Any CPU.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.EmbeddingTest|Any CPU.Build.0 = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.EmbeddingTest|Mixed Platforms.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.EmbeddingTest|Mixed Platforms.Build.0 = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.EmbeddingTest|Win32.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.EmbeddingTest|x64.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.EmbeddingTest|x86.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Release|Any CPU.Build.0 = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Release|Win32.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Release|x64.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.Release|x86.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.UnitTests|Any CPU.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.UnitTests|Any CPU.Build.0 = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.UnitTests|Mixed Platforms.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.UnitTests|Mixed Platforms.Build.0 = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.UnitTests|Win32.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.UnitTests|x64.ActiveCfg = Release|Any CPU
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2}.UnitTests|x86.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -354,5 +384,6 @@ Global
{353769D3-D11C-4D86-BD06-AC8C1D68642B} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
{6B6696B1-A547-4FD4-85EF-E1FD0F54AD2C} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
{230AE83F-E92E-4E69-8355-426B305DA9C0} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
{8C14DC11-2737-4DCB-A121-5D7BDD57FEA2} = {3A73F5A7-0335-40D8-BF7C-F20BE5D0BA87}
EndGlobalSection
EndGlobal

View File

@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
@@ -20,7 +21,7 @@ namespace Wox.PluginLoader
{
try
{
Assembly asm = Assembly.LoadFile(metadata.ExecuteFilePath);
Assembly asm = Assembly.Load(AssemblyName.GetAssemblyName(metadata.ExecuteFilePath));
List<Type> types = asm.GetTypes().Where(o => o.IsClass && !o.IsAbstract && (o.BaseType == typeof(BaseSystemPlugin) || o.GetInterfaces().Contains(typeof(IPlugin)))).ToList();
if (types.Count == 0)
{