PowerShell中的C#:使用“使用System.Linq”的错误 [英] C# in PowerShell: Errors with "using System.Linq'

查看:78
本文介绍了PowerShell中的C#:使用“使用System.Linq”的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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:


$code = @"

using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Xml;<code></code>
using System.Xml.Linq;

   public class Program
    {
        static void Main()
        {  /* the code wich works*/


        }


    }


"@
Add-Type  -TypeDefinition $code -Language "CSharpVersion3"

Powershell gives me an error saying that " The type or namespace Linq doesn't exist" , and the same for Xml. I have Visual studio express 2013 .

How can add or import correctly those references? or what is my error?

推荐答案

代码 = @

使用系统;
使用 系统 .Collections;
使用 系统 .IO;
使用系统 .Linq;
使用 系统 .Xml;< code> < / 代码 >
使用 系统 Xml .Linq;


public class 程序
{
static void Main()
{ / * 代码有效* /


}


}


@
Add-Type - TypeDefinition
code = @" using System; using System.Collections; using System.IO; using System.Linq; using System.Xml;<code></code> using System.Xml.Linq; public class Program { static void Main() { /* the code wich works*/ } } "@ Add-Type -TypeDefinition


代码 - 语言CSharpVersion3

Powershell 给出 me 呃ror The type namespace < span class =code-leadattribute> Linq 不存在 相同 Xml Visual studio express 2013

add import 正确 那些引用? 我的错误?
code -Language "CSharpVersion3" Powershell gives me an error saying that " The type or namespace Linq doesn't exist" , and the same for Xml. I have Visual studio express 2013 . How can add or import correctly those references? or what is my error?


您没有提供大量信息。您看到了什么错误?

Anywho,尝试使用Add-Type系列,看看需要多长时间:



You're not providing a whole lot of information. What errors are you seeing?
Anywho, try this for your Add-Type line and see how far that takes ya:

Add-Type -TypeDefinition


这篇关于PowerShell中的C#:使用“使用System.Linq”的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆