English 中文(简体)
加入《公约》,要求加入议会
原标题:Add-Type from cs, that requires referencing assemblies

I hava a ccs file with very brief Code:

using Ionic.Zip;
public static class Helper
{
        public static ZipFile GetNewFile(string fileName)
        {       
            return new ZipFile(fileName);
        }
}

它需要一站式。 Zip组。 我想在我的权力中增加这样的内容:

cd c:pst
Add-Type -Path "2.cs" -ReferencedAssemblies "Ionic.Zip.dll"
$var = [Helper]::GetNewFile("aaa")

当我这样做时,我给我:

The following exception occurred while retrieving member "GetNewFile": "Could not load file or assembly  Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c  or one of its dependencies. The located assembly 
s manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)"

它似乎在一些温带汇编了组装,并且可以发现一流。 在那里。

但是,如果具体指明产出组,然后添加这一组:

cd c:pst
Add-Type -Path "2.cs" -ReferencedAssemblies "Ionic.Zip.dll" -OutputAssembly "T.dll"
Add-Type -Path "T.dll"

$var = [Helper]::GetNewFile("aaa")
$var.AlternateEncoding

因此,我很想知道是否有办法避免使用产出组?

问题回答

在Powerhell诉3 CTP1 案中,你可以解决贵方图书馆的全部道路(姓名),并提及:

$ziplib = (get-item ionic.zip.dll).fullname
[void][reflection.assembly]::LoadFrom($ziplib)
Add-Type -Path "2.cs" -ReferencedAssemblies $ziplib
$var = [Helper]::GetNewFile("aaa")
$var.AlternateEncoding

You have to put your ionic.zip.dll file in the GAC then on powershell you can do this:

C:ps> [System.Reflection.Assembly]::LoadWithPartialName("ionic.zip")
C:ps> Add-Type -Path "2.cs" -ReferencedAssemblies "Ionic.Zip.dll"
C:ps> $var = [Helper]::GetNewFile("aaa")
C:ps> $var.name
aaa




相关问题
Mutually exclusive powershell parameters

SCENARIO I m writing a cmdlet for Powershell 2.0 using Visual Studio 2008 and .NET 3.5 the cmdlet requires 3 arguments. my intended grammar of the cmdlet is something like this: cmdletname [foo|...

Run a program from PowerShell with timeout

I ll write a script that runs a program and wait for it finished. But if the program is not finished within a specified time I want that the program is killed.

How to transpose data in powershell

I have a file that looks like this: a,1 b,2 c,3 a,4 b,5 c,6 (...repeat 1,000s of lines) How can I transpose it into this? a,b,c 1,2,3 4,5,6 Thanks

Powershell v2 remoting and delegation

I have installed Powershell V2 on 2 machines and run Enable-PsRemoting on both of them. Both machines are Win 2003 R2 and are joined to the same active directory domain and I can successfully run ...

PowerShell -match operator and multiple groups

I have the following log entry that I am processing in PowerShell I m trying to extract all the activity names and durations using the -match operator but I am only getting one match group back. I m ...

热门标签