Create Visual Studio Project with API from matlab
3 次查看(过去 30 天)
显示 更早的评论
Hi everyone, I have to create a visual studio project (programmatically) from Matlab, using the API present in this site
https://docs.microsoft.com/en-us/dotnet/api/envdte.projects?view=visualstudiosdk-2017. In the last folder of the path below, there are files .h and .c. Anyone has encountered a problem like this? I'm using Visual Studio 2017 and Matlab 2019b.
I show what are the APIs that I'm using that don't work:
openedVS = actxGetRunningServer('VisualStudio.DTE.15.0');
sol=openedVS.DTE.Solution;
sol.Create('C:\Users\matte\Desktop\VisualStudio','MyNewSolution');
sol.SaveAs('C:\Users\matte\Desktop\VisualStudio\MyNewSolution.sln');
proj=sol.AddFromTemplate('C:\Users\matte\Desktop\VisualStudio\ConsoleApplication1\ConsoleApplication1\ConsoleApplication1.vcxproj','C:\Users\matte\Desktop\VisualStudio','My New Project',true);
proj.ProjectItems.AddFromDirectory('C:\Users\matte\Desktop\Tesi\file generazione\file generati\');
On the last row of code I obtain the followng error:
Error using Interface.8E2F1269_185E_43C7_8899_950AD2769CCF/AddFromDirectory
Invoke Error, Dispatch Exception: Non implementato
Error in Creazione_Progetto (line 7)
proj.ProjectItems.AddFromDirectory('C:\Users\matte\Desktop\Tesi\file generazione\file generati\');
0 个评论
回答(1 个)
Aniket
2025-4-8
I am able to reproduce the error you are facing. This is actually expected behavior because ProjectItems.AddFromDirectory() is not implemented for all project types (especially VC++ projects), or not exposed through the DTE automation layer.
As a workaround, instead of using AddFromDirectory(), you’ll need to add the .c and .h files individually using AddFromFile() or AddFromFileCopy() as shown below:
folderPath = 'C:\Users\matte\Desktop\Tesi\file generazione\file generati\';
files = dir(fullfile(folderPath, '*.c'));
files = [files; dir(fullfile(folderPath, '*.h'))];
for k = 1:length(files)
fullPath = fullfile(folderPath, files(k).name);
proj.ProjectItems.AddFromFile(fullPath); % Or AddFromFileCopy if you want a copy
end
Also note that if you're trying to add these to a specific folder inside the project, like proj.ProjectItems.Item("Source Files").ProjectItems.AddFromFile(...), you’ll need to navigate through the project tree.
I hope this helps resolve the issue!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 File Operations 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!