PowerShell中的C#:如何添加多个ReferenceAssemblies [英] C# in PowerShell: how to add multiple ReferenceAssemblies
问题描述
我正在尝试在Power Shell 2.0中执行C#代码。
我的问题是代码开头的引用:
Hi , I'm trying to execute C# code in Power Shell 2.0 .
My problem is for the references at the beginning of the code:
$referencingassemblies = (
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.XML.dll",
"C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Linq.dll"
)
code= @"
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Xml;
using System.Xml.Linq;
public class Program
{
static void Main()
{ /* the code witch works*/
}
}"@
Add-Type -ReferencedAssemblies $ referencingassemblies -TypeDefinition $ code -LanguageCSharpVersion3-IgnoreWarnings
Powershell给出了一个错误,指出Linq的类型或命名空间不存在。我有Visual Studio express 2013.
如何同时正确地添加或导入两个引用?或者我做错了什么?
Add-Type -ReferencedAssemblies $referencingassemblies -TypeDefinition $code -Language "CSharpVersion3" -IgnoreWarnings
Powershell gives me an error saying that The type or namespace Linq doesn't exist. I have Visual studio express 2013.
How can add or import correctly both References at the same time?or what I'm doing wrong?
推荐答案
referencingassemblies =(
C:\ Windows \ Microoft.NET \ Framework\v4.0.30319 \ System.XML.dll,
C:\ Windows \ Microsrosoft.NET\Framework\v4.0.30319\System.Linq.dll
)
code = @
使用System;
使用System.Collections;
使用System.IO;
使用System.Linq;
使用System.Xml;
使用System.Xml.Linq;
公共类程序
{
static void Main()
{/ *代码巫婆工作* /
}
}@
referencingassemblies = ( "C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.XML.dll", "C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Linq.dll" ) code= @" using System; using System.Collections; using System.IO; using System.Linq; using System.Xml; using System.Xml.Linq; public class Program { static void Main() { /* the code witch works*/ } }"@
Add-Type -ReferencedAssemblies
Add-Type -ReferencedAssemblies
referencingassemblies -TypeDefinition
referencingassemblies -TypeDefinition
code -LanguageCSharpVersion3-IgnoreWarnings
Powershell给我一个错误说Linq的类型或命名空间不存在。我有Visual Studio express 2013.
如何同时正确添加或导入两个参考文件?或者我做错了什么?
code -Language "CSharpVersion3" -IgnoreWarnings
Powershell gives me an error saying that The type or namespace Linq doesn't exist. I have Visual studio express 2013.
How can add or import correctly both References at the same time?or what I'm doing wrong?
这篇关于PowerShell中的C#:如何添加多个ReferenceAssemblies的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!