Error Script C#

I am receiving the following error while trying to run a C# script step.

ERROR: Script compilation failed: C:\Octopus\Work\20160321132315-221\Script.csx(35,9): error CS0103: The name ‘ZipFile’ does not exist in the current context.
13:23:21Fatal
The remote script failed with exit code 1

The line I imagine is reporting this is:
System.IO.Compression.ZipFile.CreateFromDirectory(destDirName, zipPath + date + “_” + key + “.zip”);
I tried with and without the FQN with no luck.

Any ideas?

Hi Fabian,

You need to add a reference to the System.IO.Compression.Filesystem.dll in your script, like below:

#r "System.IO.Compression.FileSystem.dll"
...
System.IO.Compression.ZipFile.CreateFromDirectory(destDirName, zipPath + date + "_" + key + ".zip");
...

I hope that helps!

Thank you and best regards,
Henrik

Hi Henrik. That was the problem, thanks! I found it in another site while investigating but forgot to come here to update the issue.
Thank you!

I have a similar issue. Can anyone assist me with resolving this error:
ERROR: Script compilation failed: error CS0009: Metadata file ‘C:\Program Files (x86)\VisualCron\VisualCronAPI.dll’ could not be opened – ‘MetadataReaderException: SomeRequiredTablesNotSorted’.

I had a similar problem in link (http://help.octopusdeploy.com/discussions/questions/7848-c-post-deployment-script). Mark gave me some ideas on where to go, I ended up going to powershell.