.NET Forum / Visual Studio.NET / Extensibility / February 2006
IVsSolution::GetUniqueNameOfProject returns E_FAIL
|
|
Thread rating:  |
Don B. - 11 Feb 2006 00:17 GMT I'm getting an intermittent E_FAIL error from IVsSolution::GetUniqueNameOfProject.
I'm implementing a custom project system based on the MyC unmanaged sample project. It all works fine, except when I try to automatically add source files to the project at project creation time. In this case, I sometimes get the error described.
The call is made in my automation object that implements VxDTE::Project in the method get_UniqueName. This is called by the environment when the file is added.
I'm not sure how to address this error. It feels like a race condition. I read in the documentation or somewhere that it is a bad idea to add items to a project until it is completely created, but it isn't clear what "completely created" means in this case. Before I add the file to the project, an ItemAdded event has been fired to let the environment know the project has been created.
If I ignore the error and continue running, things appear to work OK.
Is there more information available on possible causes of E_FAIL from IVsSolution::GetUniqueNameOfProject?
What does it really do, anyway, and how does it work?
The only related topic I found was
http://msdn.microsoft.com/newsgroups/managed/default.aspx?query=AddItem&dg=micro soft.public.vstudio.extensibility&cat=en-us-msdnman-visualtools-vstudio&lang=en& cr=US&pt=bf0ebdd7-5d74-479a-b01e-d7b141200243&catlist=&dglist=&ptlist=&exp=&sloc =en-us
which recommends using a DTE automation object to add an item. I have not tried this...it seemed straightforward to just add the file to a folder node in my hierarchy.
Ideas/thoughts/help??
thanks --Don B.
"Gary Chang[MSFT]" - 13 Feb 2006 09:10 GMT Hi Din,
The GetProjectOfUniqueName will return E_FAIL when it iterates through the projects in the solution but does not find anything that matches. It may fail if you pass a uniquename which format is unlike the VB or C# project returns, such as the project2\project2.vbproj or project2\project2.csproj.
I suggest you can take a look on a related MSDN forum thread, which has a discussion on the similar problem:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=82229&SiteID=1
Wish it helps!
Best regards,
Gary Chang Microsoft Community Support ====================================================== PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00 AM PST, February 14, 2006. Please complete a re-registration process by entering the secure code mmpng2006 when prompted. Once you have entered the secure code mmpng2006, you will be able to update your profile and access the partner newsgroups. ====================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from this issue. ====================================================== This posting is provided "AS IS" with no warranties, and confers no rights. ======================================================
Don B. - 15 Feb 2006 00:21 GMT Thanks Gary. I have a better understanding of what's going on now. It seems like I need to synchronize with the VS environment after adding my project to make sure it shows up in the solution before I try to add any files to the project, because adding a file to the project triggers the call (from the VS environment) to GetUniquenameOfProject(). (Does that seem reasonable and likely?)
As I noted before, I'm firing an ItemAdded event after adding the project, but apparently I need to wait until the environment processes that event before adding files. I may be able to find some clues by digging through the code, but if you have any ideas on how this sort of synchronization is accomplished that'd be helpful and appreciated.
thanks --Don B.
> Hi Din, > [quoted text clipped - 26 lines] > This posting is provided "AS IS" with no warranties, and confers no rights. > ====================================================== "Gary Chang[MSFT]" - 15 Feb 2006 05:26 GMT Hi Don,
>As I noted before, I'm firing an ItemAdded event after adding >the project, but apparently I need to wait until the environment >processes that event before adding files. The may be the problem. Usually we add a new item to an existing project.
I suggest you take another approach--how about add the target source file to the corrspoding project template directly. If so, you don't need to add it in the project's creation time.
Thanks!
Best regards,
Gary Chang Microsoft Community Support ====================================================== PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00 AM PST, February 14, 2006. Please complete a re-registration process by entering the secure code mmpng2006 when prompted. Once you have entered the secure code mmpng2006, you will be able to update your profile and access the partner newsgroups. ====================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from this issue. ====================================================== This posting is provided "AS IS" with no warranties, and confers no rights. ======================================================
Don B. - 15 Feb 2006 18:55 GMT Gary, OK, it sounds like I'm taking the wrong approach. Just to be clear, I want to my unmanaged custom project system to create some types of projects such that they contain some template source code, in the same way that visual C++ might do for, say, a console app. You are saying that I can do this by "adding the target source file to the project template directly". In this case, does the environment copy the file to the project directory automatically?
Can you give me a pointer to documentation or an example of how to do this? I don't see anything in the VSSDK docs under "Adding Projects and Project Items".
thank you --Don B.
> I suggest you take another approach--how about add the target source file > to the corrspoding project template directly. If so, you don't need to add [quoted text clipped - 3 lines] > Gary Chang > Microsoft Community Support "Gary Chang[MSFT]" - 16 Feb 2006 08:12 GMT Hi Don,
>In this case, does the environment copy the file to the >project directory automatically? yes, those source file would be created as well as the project file in the same time.
>documentation or an example of how to do this? I suggest you can refer to the following MSDN articles for how create a project template and deploy it:
How to: Create Project Templates http://msdn2.microsoft.com/en-us/library(d=robot)/xkh1wxd8.aspx
How to: Locate and Organize Project and Item Templates http://msdn2.microsoft.com/en-us/library/y3kkate1.aspx
Visual Studio SDK Deploying Project and Project Item Templates ms-help://MS.VSCC.v80/MS.VSIPCC.v80/MS.VSSDK.v80/dv_search/html/998a2df1-c1c 4-4328-921b-bc7e9fc4a0dc.htm
Thanks!
Best regards,
Gary Chang Microsoft Community Support ====================================================== PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00 AM PST, February 14, 2006. Please complete a re-registration process by entering the secure code mmpng06 when prompted. Once you have entered the secure code mmpng06, you will be able to update your profile and access the partner newsgroups. ====================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from this issue. ====================================================== This posting is provided "AS IS" with no warranties, and confers no rights. ======================================================
Don B. - 17 Feb 2006 23:15 GMT > Hi Don, > [quoted text clipped - 38 lines] > This posting is provided "AS IS" with no warranties, and confers no rights. > ====================================================== Don B. - 18 Feb 2006 00:56 GMT [Something bad happened to my previous reply. 2nd try.]
I haven't made much forward progress with this problem. I tried several approaches to using templates with my project system without much success.
What I tried: ---------------- (1) File->Export Template is grayed out under my project system (same as for VC) (2) I followed the documentation's instructions on manually creating a project template (XML file, send to zip, put zip in project templates dir, etc.). Nothing showed up in my Add New Project dialog. (3) I tried just putting the .vstemplate file in my project templates dir (the one where my .vsdir file lives). In this case there was an item in the dialog for the template, and when I clicked on it it created a project and ran through much of my project creation code, but didn't really follow the usual rules about naming and so on, and finally bombed out with "method or function not implemented". I don't know what was unimplemented.
Concerns: ------------- I am concerned that this approach may be a mismatch for my native project system implementation. Most of the template documentation seems to be associated with managed code. There's not much doc'n about templates in the VSSDK docs except how to install them.
Let me summarize to make sure we are on the same page: ---------------------------------------------------------------------- (1) I am implementing a custom native project system using ATL/COM and based on the unmanaged MyC sample project system. (2) The target platform is also native (not CLR) (3) The Add New Project dialog is populated using a .vsdir file (4) The problem I am trying to solve is to have project types such that when they are created, there is template source code already copied into the project directory and added to the project. My original approach, to copy the file in and add it programmatically just after creating the project, *almost* works. It seems that for this approach to work, some synchronization is req'd to notify my project system that the project has been successfully added to the solution so I don't add the file to the project too soon.
Questions: ------------- - will vs templates work with native project system implementations ? - will vs templates work with .vsdir files? - are there VSIP COM interfaces that the project system must implement to support templates? - should this just work? do you suspect I'm just doing something wrong? - is there a way to synchronize on the project being added to the sol'n? IVsSolution or IVsSolutionEvents? - are there other alternatives to solve this? (seems like it should be a common issue...)
thanks yet again, Don B.
> Hi Don, > [quoted text clipped - 38 lines] > This posting is provided "AS IS" with no warranties, and confers no rights. > ====================================================== "Gary Chang[MSFT]" - 21 Feb 2006 09:38 GMT Hi Don,
It appears the instruction about manually creating a project template doesn't apply to a custom unmanaged project system. I will contact our VSIP specialists to look into this issue.
We will reply you with more information soon.
Thanks for your understanding!
Best regards,
Gary Chang Microsoft Community Support ====================================================== PLEASE NOTE the newsgroup SECURE CODE and PASSWORD will be updated at 9:00 AM PST, February 14, 2006. Please complete a re-registration process by entering the secure code mmpng06 when prompted. Once you have entered the secure code mmpng06, you will be able to update your profile and access the partner newsgroups. ====================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from this issue. ====================================================== This posting is provided "AS IS" with no warranties, and confers no rights. ======================================================
Mike Wong (Microsoft) - 22 Feb 2006 22:33 GMT Hi Don,
Gary sent me some mail asking about creating a template based on your project type. The easiest approach right now would be to take the same approach as the VC++ wizards. Use the old wizard approach right now with your MyC based project system. Here are some steps you can take to create a traditional wizard that will work with the myc project system. I believe the vstemplate approach requires certain automation objects to be in place for your project system so we'll need to document that in the future. The old wizard approach (the wizards that were used in VS.NET 2002/2003, also require automation but myc implements just enough for this to work) VsProject object typed projects support the newer approach so if you had a VB/C#/J# type project then the vstemplate approach would be the way to go. You already noticed that VC++ projects use the older approach described below.
1) In Visual Studio 2005, go to File | New Project | Visual C++ | Custom Wizard 2) Remove default.vcproj underneath the miscellaneous files folder. (Select the node in solution explorer, right click, select Remove) 3) Copy an empty project file (0 bytes) into the wizard directory i.e. mycproject.mycp. For testing, you might need to copy it to C:\Program Files\Microsoft Visual Studio 8\VC\VCWizards as well so the code in default.js can find it. 4) Right click on the Miscellaneous folder and select add existing item to add mycproject.mycp you copied to your wizard directory. 5) Modify default.js like the following function OnFinish(selProj, selObj) { try { var strProjectPath = wizard.FindSymbol('PROJECT_PATH'); var strProjectName = wizard.FindSymbol('PROJECT_NAME');
selProj = CreateCustomProject(strProjectName, strProjectPath); var InfFile = CreateCustomInfFile(); AddFilesToCustomProj(selProj, strProjectName, strProjectPath, InfFile); InfFile.Delete();
} catch(e) { if (e.description.length != 0) SetErrorInfo(e); return e.number } }
function CreateCustomProject(strProjectName, strProjectPath) { try { .. strProjTemplate = strProjTemplatePath + '\\mycProject.mycp'; .. strProjectNameWithExt = strProjectName + '.mycp'; .. }
function GetTargetName(strName, strProjectName) { .. try { //the name below should match to any files you are adding to the project and to any files you add to templates.inf. I have one source file named t01.myc that //I want named to sourcefile1.myc when the the project is created if (strName == 't01.myc') strTarget = 'sourcefile1.myc'; return strTarget; .. }
function AddFilesToCustomProj(proj, strProjectName, strProjectPath, InfFile) { .. //change the following line //proj.Object.Add(strFile) to projItems.AddFromFile(strFile); }
The above is one example how wizards need certain automation functions implemented since it would be harder to go through IVsProject::AddItem in a wizard.
Add files to the templates.inf file and template files folder that you want to add to your new project. Make sure you modify the GetTargetName function in default.js above.
For example my templates.inf file has the following entry: t01.myc
After testing, you'll deploy the vsdir, vsz, ico file for your wizard, to the directory specified in HKLM\Software\VisualStudio\8.0(Exp)\Projects\{project guid} named value: ProjectTemplatesDir c:\Program Files\Visual Studio 2005 SDK\2005.10\VisualStudioIntegration\Archive\MyCPkgs\MyCPrj\MyCPrjProjects
I can also send you mywizard that I created that demonstrates (mikewong@onlinemicrosoft.com) take the online out of the address.
With wizards, you can debug into the script by going to
Start 2 instance of the ide (devenv.exe). From one instance, open up the js file that you want to debug into. Set the appropriate breakpoints. from the same instance in step 2, select Debug | Attach to process. In the available processes list, select the other instance of devenv.exe In the same attach to process dialog, click on the select… button, check the box for “Script” Click on OK Click on Attach. In the second instance go to File | New Project or any other steps to exercise the wizard. We should hit the breakpoints.
That will be useful when you need to step through the js file to see what the values are.
I hope that helps.
Thanks! Mike Wong Microsoft Developer Support
Mike Wong (Microsoft) - 23 Feb 2006 03:43 GMT Hi Don,
I got the mail you sent me but my mail back to you keeps getting bounced back. Could you send me another mail to my email address?
much appreciated, mike
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|