Add A Module Template To Project

M

Mythran

I'm trying to add a module template to a project programmatically. I've tried
many documented (w/o examples) ways of doing it to no avail. For example, I
tried using Project.ProjectItems.AddFromTemplate("C:\Program Files\Microsoft
Visual Studio .NET 2003\Vb7\VBWizards\Module\Templates\1033\Module.vb",
"Common.vb") and this adds it ok. Problem is, it does not replace the [!
directives with the proper values. ([!output SAFE_FILE_NAME] stays as such). So
I tried the DTE.LaunchWizard method and passed in the "proper" values, but I keep
getting an error "Unspecified Error" message with 1 of two return codes
(0x80004004 or 0x80041FFF). Looked up both error values on google and msdn and
found 1 (more but all same thing) result, "Unspecified Error". Doesn't help.

Any help would be appreciated.

Thank you,
Mythran
 
S

Steve Baker

Mythran,

Did you ever resolve this? I would like to run nunit tests to verify
my output, something like:

Public Sub BusinessExceptionTest()
Dim proj As Project = DTE.ActiveSolutionProjects(0)

Dim params() As Object = New Object()
{EnvDTE.Constants.vsWizardAddItem,
proj.Name,
proj.ProjectItems,
tempDirectory,
"nUnitItem",
VS_NET_INSTALL_DIR, True}

Dim result As EnvDTE.wizardResult
result = DTE.LaunchWizard("test.vsz"), params)

Dim verified As String = GetFileText("")
Dim created As String = GetFileText("")

Assert.AreEqual(verified, created)
End Sub


I am getting the same error :(

Thank you,

Steve
 
M

Mythran

Yes...

I found that it is a problem...bug...I believe. Haven't had anyone else test it
though...

1.) Use AddFromTemplate with parameter of the path to the vbscript.vsz file.
2.) Delete the returned item.
3.) Use AddFromTemplate with parameter of the path to the VSZ file for the
project item you want to add.


The same problem that you had with the LaunchWizard function is fixed if you
first add a blank wizard first...the fix is basically to first use
AddFromTemplate or LaunchWizard and give the parameter to a VSZ file that
corresponds to a file without any [!output] directives in it...such as the
vbscript.vsz (the vbscript.vbs file doesn't have any [!output] directives in it,
therefore it works)...

I have no other workarounds at this time :(

Mythran

P.S. I might have a working solution, but haven't tried it...in the default.js
script, try placing the following before selObj or selProj is accessed:

selProj = (selProj == null ? selObj.ContainingProject : selProj);

It might work....if selObj.ContainingProject is undefined, try
selObj.Parent.ContainingProject...

Steve Baker said:
Mythran,

Did you ever resolve this? I would like to run nunit tests to verify
my output, something like:

Public Sub BusinessExceptionTest()
Dim proj As Project = DTE.ActiveSolutionProjects(0)

Dim params() As Object = New Object()
{EnvDTE.Constants.vsWizardAddItem,
proj.Name,
proj.ProjectItems,
tempDirectory,
"nUnitItem",
VS_NET_INSTALL_DIR, True}

Dim result As EnvDTE.wizardResult
result = DTE.LaunchWizard("test.vsz"), params)

Dim verified As String = GetFileText("")
Dim created As String = GetFileText("")

Assert.AreEqual(verified, created)
End Sub


I am getting the same error :(

Thank you,

Steve

I'm trying to add a module template to a project programmatically. I've tried
many documented (w/o examples) ways of doing it to no avail. For example, I
tried using Project.ProjectItems.AddFromTemplate("C:\Program Files\Microsoft
Visual Studio .NET 2003\Vb7\VBWizards\Module\Templates\1033\Module.vb",
"Common.vb") and this adds it ok. Problem is, it does not replace the [!
directives with the proper values. ([!output SAFE_FILE_NAME] stays as such). So
I tried the DTE.LaunchWizard method and passed in the "proper" values, but I keep
getting an error "Unspecified Error" message with 1 of two return codes
(0x80004004 or 0x80041FFF). Looked up both error values on google and msdn and
found 1 (more but all same thing) result, "Unspecified Error". Doesn't help.

Any help would be appreciated.

Thank you,
Mythran
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top