簡體   English   中英

CSC生成時間的CSC命令參數用法

[英]CSC Command Parameters Useage for C# Build Time

ParseXSD.cs

using System;
using System.Collections;
using System.Xml;
using System.Xml.Schema;


class XmlSchemaTraverseExample
{
    static void Main()
    {
        // Add the customer schema to a new XmlSchemaSet and compile it.
        // Any schema validation warnings and errors encountered reading or 
        // compiling the schema are handled by the ValidationEventHandler delegate.
        XmlSchemaSet schemaSet = new XmlSchemaSet();
        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
        schemaSet.Add("http://www.w3.org/2001/XMLSchema", "tmp.xsd");
        schemaSet.Compile();

        // Retrieve the compiled XmlSchema object from the XmlSchemaSet
        // by iterating over the Schemas property.
        XmlSchema customerSchema = null;
        foreach (XmlSchema schema in schemaSet.Schemas())
        {
            customerSchema = schema;
        }

        // inserted more code here....
}

}

目前,我的ConsoleApp運行良好。

我想從下面的代碼中刪除硬代碼(xsd文件路徑)。

//我不知道如何更新此行。

schemaSet.Add("http://www.w3.org/2001/XMLSchema", "tmp.xsd"); 

然后,我可以使用下面的CSC命令在構建時運行我的ParseXSD.cs文件。

//我不知道正確的命令格式。 我可以輕松更新path參數。 沒有硬代碼。

 CSC ParseXSD.cs d:/tmp/tmp.xsd  

請給我一些指導。 提前致謝。

您要在編譯時還是在運行時指定它?

在運行時更改時執行

static void Main()

static void Main(string[] args)

接着

schemaSet.Add("http://www.w3.org/2001/XMLSchema", args[0]);

如果要在編譯時指定它,則可以使用precompile指令來執行它,但是我不確定是否可以為csc指定它們。 您的另一個選擇是在使用命令行腳本或類似腳本編譯之前進行注入。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM