Noa

Hi,

I am trying to write a wizard to add new item to VS 2005.

I followed the instructions in the Walkthrough: Creating a Wizard in Dev Tools & Languages > VS > IDE > Customizing and Automating the Development Environment > Automation and Extensibility for Visual Studio > Creating Add-ins and Wizards, but I keep getting an error "Invalid at the Top Level of the Document" whenever choosing the new item I just added.

Are the instructions missing something Does it refer to an older version of VS

How can I create a wizard to add new item to a project

Thanks.



Re: Visual Studio Extensibility New Item wizards in VS 2005

Craig Skibo

The XML is probably malformed. Things to try are make sure the < xml ...> is correct, the encoding style in the < xml> tag matches the encoding the file was saved to, etc. If you atach the first few lines of the XML file we can take a quick look to make sure it is correct.

Craig






Re: Visual Studio Extensibility New Item wizards in VS 2005

Noa

which XML

in the walktrough I went with, there was only a .vsz file, which is not XML.





Re: Visual Studio Extensibility New Item wizards in VS 2005

Craig Skibo

You can create the vsz file using either plain text or an XML file. We try to read in the file as plain text, and if it fails (for any number of reasons), then we try to read it as XML. The error is from the XML parser, so I assumed that you were using the XML form of this file.

The error, though, is probably format related. If the file contains any unicode characters (meaning it was saved to any format other than ANSI), or if you have blank lines at the top of the document, etc, then we try to read it as XML. If the file is supposed to be the plain-text version but failed for some reason, then the XML format will also fail to load and you will see this error.

You can send me the .vsz file directly (craigs@microsoft.com), and I can look at it to see if I spot anything.

Craig






Re: Visual Studio Extensibility New Item wizards in VS 2005

Matt.Lin

Hi,Noa

i can write a wizard to add new item to VS 2005 as the same thing you can do in VS 2003,customing the standard VsWizardEngine of VS 2005,

you can write the .vsz file like below:

VSWIZARD 7.0
Wizard=VsWizard.VsWizardEngine.8.0
Param="WIZARD_NAME =
AddMyCustomFormWizCS
"
Param="WIZARD_UI = FALSE"
Param="PROJECT_TYPE = CSPROJ"

after that, you can create folder named the same "AddMyCustomFormWizCS",and in this folder ,you can create two

subfolder Scripts,Templates,in these folder there is a subfloder named by codepage(1033),i use chinese version so it is 2052,there is a default.js file in Scripts/1033 folder, some templates file items in Templates/1033 folder which you will copy to destination project later,

in the default.js file ,you can write DTE Wizard eventhandler like below:

 

var L_RptWizError_ErrorAddingRefs ="Error in adding references for the new report: ";

function OnFinish(selProj, selObj)
{
    var oldSuppressUIValue = true;
    try
    {
        var strTarget = wizard.FindSymbol("ITEM_NAME");
        var strClassName = strTarget.split(".");
        var bValid = wizard.ValidateCLRIdentifier(strClassName[0]);
        if (!bValid)
            return VS_E_WIZARDBACKBUTTONPRESS;

        var strUpperClassName = strClassName[0].toUpperCase();
        if (strUpperClassName == "DETAIL" || strUpperClassName == "PAGEFOOTER" || strUpperClassName == "PAGEHEADER") {
            wizard.ReportError("A report can't be named 'Detail', 'PageHeader' or 'PageFooter'. Please specify another name.");
            return VS_E_WIZARDBACKBUTTONPRESS;
        }

        oldSuppressUIValue = dte.SuppressUI;
        var strProjectName        = wizard.FindSymbol("PROJECT_NAME");
        var strSafeProjectName = CreateSafeName(strProjectName);
        wizard.AddSymbol("SAFE_PROJECT_NAME", strSafeProjectName);
        SetTargetFullPath(selObj);
        var strProjectPath        = wizard.FindSymbol("TARGET_FULLPATH");
        var strTemplatePath        = wizard.FindSymbol("TEMPLATES_PATH");

        var strTpl = "";
        var strName = "";
        var InfFile = CreateInfFile();
        AddReferencesForComponent(selProj);
        AddReferencesForReport(selProj);
        AddFilesToCSharpProject(selObj, strProjectName, strProjectPath, InfFile, true );
    }
    catch (e)
    {
        if (e.description.length > 0)
            SetErrorInfo(e);
        return e.number;
    }
    finally
    {
        dte.SuppressUI = oldSuppressUIValue;
        if( InfFile )
            InfFile.Delete();
    }
}

function SetFileProperties(oFileItem, strFileName)
{
    // get file extension
    if (strFileName == "NewXtraReportV3.cs")
    {
        oFileItem.Properties("SubType").Value = "Component";
    }
}

function AddReferencesForReport(oProj)
{
    try
    {
        var refmanager = GetCSharpReferenceManager(oProj);
        var bExpanded = IsReferencesNodeExpanded(oProj)
        refmanager.Add("DevExpress.XtraReports3");
        refmanager.Add("DevExpress.XtraPrinting3");
        refmanager.Add("DevExpress.Utils3");
        refmanager.Add("DevExpress.Data3");
        refmanager.Add("System.Drawing");
        if(!bExpanded)
            CollapseReferencesNode(oProj);
    }
    catch (e)
    {
        wizard.ReportError(L_RptWizError_ErrorAddingRefs + e.description);
    }
}

function GetCSharpTargetName(strName, strProjectName)
{
    var strTarget = strName;
    if (strName == "NewXtraReportV3.cs")
        strTarget = wizard.FindSymbol("ITEM_NAME");

    return strTarget;
}

 






Re: Visual Studio Extensibility New Item wizards in VS 2005

Matt.Lin

you can get some more info from

http://aspalliance.com/309

and vs MSDN help from this

ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.VisualStudio.v80/dv_vcide/html/7f0e393c-395e-491b-add2-904cf8838e81.htm






Re: Visual Studio Extensibility New Item wizards in VS 2005

Augustin Calin

Sorry, Craig, but I have the same problem and my vsz file is plain ANSI text file, containing exactly the lines shown in walkthrough ( http://msdn2.microsoft.com/7k3w6w59.aspx ), without blank lines in top.

You said that, if reading the text file fails, you are trying to read it as an XML. What's the schema for this XML






Re: Visual Studio Extensibility New Item wizards in VS 2005

Flying B

I had same problem with the VSZ file. As it turned out, the error message was missleading. I forgot to make my class public and thus the COM registration didn't register a single class. So VS was reading the VSZ file but failed to instantiate the wizard class and gave me this error message.



Re: Visual Studio Extensibility New Item wizards in VS 2005

kele

would someone be kind to tell me whether I can develop an item template and deploy it so that I can use this item template through New Item popup window regardless I am currently opening a windows form project or web site project how to reach it

meanwhile, I noticed that the generated code class implements hte IDTWizard contained in envdte.dll after following the built-in Visual Studio Addin Wizard, but I follow MSDN "how to use custom wizard with project template" article, the class implements Microsoft.VisualStudio.TemplateWizard.IWizard interface.

what's the difference between them and as to these .vsdir and .vsz files, how to utilize them

thanks in advance.

Regards