Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > PowerShell

Vista - Creating a cmdlet using csc.exe - missing namespaces

Reply
 
Old 09-21-2007   #1 (permalink)
Marco Shaw


 
 

Creating a cmdlet using csc.exe - missing namespaces

I've got some C# code to create a custom cmdlet with these statements:

....
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
....

My compile fails:
PSH> csc /t:library /r:$ref testweather2.cs
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.1378
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.

testweather2.cs(65,13): error CS0246: The type or namespace name
'Collection' could not be found (are you missing a
using directive or an assembly reference?)
testweather2.cs(69,13): error CS1579: foreach statement cannot operate
on variables of type
'Collection<System.Management.Automation.PSObject>' because
'Collection<System.Management.Automation.PSObject>'
does not contain a public definition for 'GetEnumerator'
PSH>

So I'm figuring I need to add a couple of references. I'm assuming I
need to go and find the DLLs for:
1. System.Collections
2. System.Collections.Generic
3. System.Collections.ObjectModel

Are they normally hidden? I can't seem to find them.

Visual Studio C# Express 2005 doesn't have a problem with them though,
and can compile my code without errors.

That also brings up another point, if the path has spaces, I've not been
able to figure out how to add a reference with spaces to csc.exe. Tried
quotes, casting it to a string... I can't figure it out.

Marco


--
----------------
PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com

My System SpecsSystem Spec
Old 09-21-2007   #2 (permalink)
Oisin Grehan


 
 

Re: Creating a cmdlet using csc.exe - missing namespaces

On Sep 21, 2:49 pm, Marco Shaw <marco.shaw@_NO_SPAM_gmail.com> wrote:
Quote:

> I've got some C# code to create a custom cmdlet with these statements:
>
> ...
> using System.Collections;
> using System.Collections.Generic;
> using System.Collections.ObjectModel;
> ...
>
> My compile fails:
> PSH> csc /t:library /r:$ref testweather2.cs
> Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.1378
> for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
> Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
>
> testweather2.cs(65,13): error CS0246: The type or namespace name
> 'Collection' could not be found (are you missing a
> using directive or an assembly reference?)
> testweather2.cs(69,13): error CS1579: foreach statement cannot operate
> on variables of type
> 'Collection<System.Management.Automation.PSObject>' because
> 'Collection<System.Management.Automation.PSObject>'
> does not contain a public definition for 'GetEnumerator'
> PSH>
>
> So I'm figuring I need to add a couple of references. I'm assuming I
> need to go and find the DLLs for:
> 1. System.Collections
> 2. System.Collections.Generic
> 3. System.Collections.ObjectModel
>
> Are they normally hidden? I can't seem to find them.
>
> Visual Studio C# Express 2005 doesn't have a problem with them though,
> and can compile my code without errors.
>
> That also brings up another point, if the path has spaces, I've not been
> able to figure out how to add a reference with spaces to csc.exe. Tried
> quotes, casting it to a string... I can't figure it out.
>
> Marco
>
> --
> ----------------
> PowerGadgets MVPhttp://www.powergadgets.com/mvp
>
> Blog:http://marcoshaw.blogspot.com
Hi Marco,

What's the value of $ref ?

The reason I ask is that I had some hilarious problems before like
this using codegen whereby I omitted the output name and the compiler
took the last reference argument I provided and generated the output
file using this name (e.g. System.Data.dll) and overwrote the real
system.data.dll in the framework directory. Subsequent compilations
failed even worse then because the compiler was referencing _my_
recently created system.data.dll, not the real one (which was now
deleted from the hd). Let me tell you it took a while to find that
one...

- Oisin

- Oisin

My System SpecsSystem Spec
Old 09-21-2007   #3 (permalink)
Marco Shaw


 
 

Re: Creating a cmdlet using csc.exe - missing namespaces

Quote:

> What's the value of $ref ?
Sorry...

PSH> $ref
C:\WINDOWS\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll

Marco

--
----------------
PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 10-02-2007   #4 (permalink)
Lee Holmes [MSFT]


 
 

Re: Creating a cmdlet using csc.exe - missing namespaces

Another helpful way to get $ref is:

$ref = [PsObject].Assembly.Location

--
Lee Holmes [MSFT]
Windows PowerShell Development
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.

"Marco Shaw" <marco.shaw@_NO_SPAM_gmail.com> wrote in message
news:OW0KMxK$HHA.3848@xxxxxx
Quote:

>
Quote:

>> What's the value of $ref ?
>
> Sorry...
>
> PSH> $ref
> C:\WINDOWS\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll
>
> Marco
>
> --
> ----------------
> PowerGadgets MVP
> http://www.powergadgets.com/mvp
>
> Blog:
> http://marcoshaw.blogspot.com

My System SpecsSystem Spec
Old 10-02-2007   #5 (permalink)
Marco Shaw


 
 

Re: Creating a cmdlet using csc.exe - missing namespaces

Lee Holmes [MSFT] wrote:
Quote:

> Another helpful way to get $ref is:
>
> $ref = [PsObject].Assembly.Location
>
> --
> Lee Holmes [MSFT]
> Windows PowerShell Development
> Microsoft Corporation
> This posting is provided "AS IS" with no warranties, and confers no rights.
Doesn't this get it from the GAC, and is considered not-a-good-thing?

Marco

--
----------------
PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Old 10-03-2007   #6 (permalink)
Marco Shaw [MVP]


 
 

Re: Creating a cmdlet using csc.exe - missing namespaces

Marco Shaw wrote:
Quote:

> I've got some C# code to create a custom cmdlet with these statements:
>
> ...
> using System.Collections;
> using System.Collections.Generic;
> using System.Collections.ObjectModel;
> ...
I thought I had posted an update, but don't see it. Turns out I was
just missing a directive. It was just a mix up of files I was using to
test csc.exe and VS C# Express.

Marco

--
Microsoft MVP - Windows PowerShell
http://www.microsoft.com/mvp

PowerGadgets MVP
http://www.powergadgets.com/mvp

Blog:
http://marcoshaw.blogspot.com
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Quest AD cmdlet -what is the cmdlet to remove computer object PowerShell
Invoking Cmdlet Get-Location from cmdlet,cant get Currnt Directory PowerShell
Missing cmdlet PowerShell
Creating cmdlet help PowerShell
Creating new functions using new-item cmdlet PowerShell


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46