oleg-shilo / cs-script

C# scripting platform
http://www.cs-script.net
MIT License
1.61k stars 235 forks source link

error MSB1001: Unknown switch. #268

Closed AlGantori closed 2 years ago

AlGantori commented 2 years ago

Now trying to work in VSCode, the script was working a couple years ago.

That's all I get in the terminal, I can't tell which line(s) it's not happy with, let me know what you think. Thank you.

image

My scripts starts something like this


//
// 20170310
// Quran - AayaByAaya AMS-XML Generation needed by QURAN4CHILDREN (and RECITERS)
// - Extracts ENGLISH and ARABIC fields from first PPT slide into PLAY/DARC01.XML
// - Custom Mapping/Naming of images/sounds files.
//
// To debug in VS2013 IDE link file in PULIB4/SRC.NET/VRUSLIB.TESTER/VRUSLIB.TESTER.sln
//css_args /ac
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Xml.Linq;
using System.Xml;
// using System.Diagnostics.Debug;
using System;
//
// DNOTE: these DLLs can be 1) in the GAC. Use respective INSTALL_TO_GAC.CMD
// or 2) currently directly referenced below
using VR.USLib4;
using VR.PPTLibs;
using VR.AMSUtils;
using AMSData.Mono;
using VR.Utils;
using VR.QS.Data;
//
// -) next line detects if we are running as a cs-script define flag CS_SCRIPT 
//css_co /define:CS_SCRIPT;
#if CS_SCRIPT
// -) use direct references to DLL to access latest (easier management)
//css_ref S:\_W\CONTROLS.WPF\VRQS\SRC\QSData.WPF\bin\Debug\VR.QS.Data.WPF.dll;
//css_ref S:\_W\ARP\AMSSTUDIO\SRC\AMSUtils\bin\Debug\VR.AMSUtils.dll;
//css_ref S:\_W\PULIB4\SRC.NET\MumtiLib\bin\Debug\VR.MumtiLib.DLL;
//css_ref S:\_W\CONTROLS.NET\VRPPTLibs\SRC.NET\PPTLibs\bin\Debug\VR.PPTLibs.dll;
//css_ref S:\_W\CONTROLS.WPF\VRUtils\SRC\VRUtils.WPF\bin\Debug\VRUtils.WPF.dll;
//css_ref S:\_W\PULIB4\SRC.NET\VRUSLIB\bin\Debug\VR.USLib4.DLL;
#endif
//----------------------------------------------------------------------
// if NOT in CS_SCRIPT, eg. VisualStudio then wrap our main() into a class
#if ! CS_SCRIPT
// for PPT Making and Image Export see separate script.
// S:\_W\ARP_WEB\SRC\RC_ARABIC =  مصادر عربية\QURAN\BMP\AAYABYAAYA
// 20150614
public class DeployToProduction_QURAN4CHILDREN_AayaByAaya_AMSXML
{
#endif
```.

I have just installed CSScript and MonoDebug extensions...

![image](https://user-images.githubusercontent.com/11699920/146622609-3f10416f-0a7c-47ce-ad42-65b38e81bee6.png)

.END.
oleg-shilo commented 2 years ago

The problem you are experiencing is caused by the fact that your code is passing the compiler option /define, which is invalid for the compiler engine that is the default for the current cs-script. Thus the engine you are using is dotnet.exe but it does not accept /define switch so it complains.

You can fix it by either dropping the that switch (//css_co /define:CS_SCRIPT). CS_SCRIPT will be defined unconditionally anyway.

Or you can switch to the old engine that is csc.exe. You can control the engine with the //css_engine directive.

//css_args /ac
//css_ng csc
AlGantori commented 2 years ago

Hi, thanks for the pointer removing the /define fixed that complaint. I found the main CSScript DOC/HELP here: https://github.com/oleg-shilo/cs-script/wiki

Info about compiler engines selection here: https://github.com/oleg-shilo/cs-script/wiki/Choosing-Compiler-Engine

Info about CLI arguments here: https://github.com/oleg-shilo/cs-script/wiki/CS-Script---Command-Line-Interface

My script is not running yet, I have the following next issue:

Could not load file or assembly 'System.Windows.Extensions, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

image

AlGantori commented 2 years ago

By file-linking the same script file into a VS2019 solution I am able to run the exact same script inside Visual Studio without any errors.

Initially I thought the error above "Could not load file or assembly 'System.Windows.Extensions" had to do with the script imports, but after some wrestling I managed to re-reference the OFFICE and PowerPoint interop DLLs from Office 2013. Compiling and running worked fine under Visual Studio thereafter.

However, under VSCode / CSScript it compiles OK but the error above remains. Let me know if you have any ideas. Thank you.

oleg-shilo commented 2 years ago

It may have something to do with the .NET5 bridge mode for loading .NET Framework assemblies. As a very naive fix try to put on top //css_winapp switch. it will let the engine to do assembly probing in the windows desktop assemblies folder.

If it does not help then share with me the hello world script that exhibits this problem and I will have a look.

AlGantori commented 2 years ago

Thank you, that switch //css_winapp made it run without errors image

All my projects target .NET 4.5.2 if that has anything to do with it??? (something I was forced the years to do, if my brain peanuts are right, I tried to target the lowest version). image

oleg-shilo commented 2 years ago

Yes, it is directly related. //css_winapp is a switch that forces .NET Core runtime to redirect the execution to the .NET Framework CLR, which is responsible for running windows applications.

And since you are actually targeting .NET Framework (4.5.2) the switch is what you need. BTW