N
NachoShaw
Guest
Hi
I am writing a lot of BLL DAL classes for data so decided to make a code generator for speed. That works great and has reduced my coding time exponentially over the past week. I decided to make this as an addin to create the .vb files, place them into my project folder then add them to the project programatically. I have been using this Class but im having some issues with it.
Friend Sub AddToProject(ByVal ProjName As String, ByVal FilePath As String, ByVal FileName As String, ByVal SubFolder As String)
Dim p = GlobalProjectCollection.LoadedProjects.FirstOrDefault(Function(pr) pr.FullPath = ProjName)
If p Is Nothing Then p = New Microsoft.Build.Evaluation.Project(ProjName)
p.ReevaluateIfNecessary()
Dim folderLoc = System.IO.Path.Combine(SubFolder)
If p.Items.FirstOrDefault(Function(i) i.EvaluatedInclude = folderLoc) Is Nothing Then p.AddItem("Folder", folderLoc)
Dim fileLoc = System.IO.Path.Combine(SubFolder, FileName & ".vb")
If p.Items.FirstOrDefault(Function(i) i.EvaluatedInclude = fileLoc) Is Nothing Then p.AddItem("Compile", fileLoc)
p.Save()
End Sub
I browse to the project using a file dialog and select vbproj file which is then passed in the call as 'GetFilePath'. I then call it like this
Dim BLLPath As String = System.IO.Path.Combine(GetFolderPath, "Data", "BLL", GetClassName & ".vb")
Dim DALPath As String = System.IO.Path.Combine(GetFolderPath, "Data", "DAL", GetClassName & ".vb")
'check if folders exist, create if they dont
FileOrDirExists(System.IO.Path.Combine(GetFolderPath, "Data", "BLL"))
FileOrDirExists(System.IO.Path.Combine(GetFolderPath, "Data", "DAL"))
'save BLL to the folder path
Dim BLLText As String = Xucbll1.TxtOutput.Text
My.Computer.FileSystem.WriteAllText(BLLPath, BLLText, False)
'save DAL to the folder path
Dim DALText As String = Xucbll1.TxtDALOutput.Text
My.Computer.FileSystem.WriteAllText(DALPath, DALText, False)
Dim AP As New AddToProject
AP.AddToProject(GetProject, GetFolderPath, GetClassName, "Data\BLL")
AP.AddToProject(GetProject, GetFolderPath, GetClassName, "Data\DAL")
and the 2 files are added to the project folder Data/BLL & Data/DAL folders.
The files are added to the project and then im prompted for a project reload. The problem is once that process is complete. My project settings get an error
So, something is operating properly. Can anyone identify where i am going wrong?
Thanks
I am here to ask questions and learn from others. Cor Ligthert DO NOT REPLY TO ANY OF MY POSTS!!
Continue reading...
I am writing a lot of BLL DAL classes for data so decided to make a code generator for speed. That works great and has reduced my coding time exponentially over the past week. I decided to make this as an addin to create the .vb files, place them into my project folder then add them to the project programatically. I have been using this Class but im having some issues with it.
Friend Sub AddToProject(ByVal ProjName As String, ByVal FilePath As String, ByVal FileName As String, ByVal SubFolder As String)
Dim p = GlobalProjectCollection.LoadedProjects.FirstOrDefault(Function(pr) pr.FullPath = ProjName)
If p Is Nothing Then p = New Microsoft.Build.Evaluation.Project(ProjName)
p.ReevaluateIfNecessary()
Dim folderLoc = System.IO.Path.Combine(SubFolder)
If p.Items.FirstOrDefault(Function(i) i.EvaluatedInclude = folderLoc) Is Nothing Then p.AddItem("Folder", folderLoc)
Dim fileLoc = System.IO.Path.Combine(SubFolder, FileName & ".vb")
If p.Items.FirstOrDefault(Function(i) i.EvaluatedInclude = fileLoc) Is Nothing Then p.AddItem("Compile", fileLoc)
p.Save()
End Sub
I browse to the project using a file dialog and select vbproj file which is then passed in the call as 'GetFilePath'. I then call it like this
Dim BLLPath As String = System.IO.Path.Combine(GetFolderPath, "Data", "BLL", GetClassName & ".vb")
Dim DALPath As String = System.IO.Path.Combine(GetFolderPath, "Data", "DAL", GetClassName & ".vb")
'check if folders exist, create if they dont
FileOrDirExists(System.IO.Path.Combine(GetFolderPath, "Data", "BLL"))
FileOrDirExists(System.IO.Path.Combine(GetFolderPath, "Data", "DAL"))
'save BLL to the folder path
Dim BLLText As String = Xucbll1.TxtOutput.Text
My.Computer.FileSystem.WriteAllText(BLLPath, BLLText, False)
'save DAL to the folder path
Dim DALText As String = Xucbll1.TxtDALOutput.Text
My.Computer.FileSystem.WriteAllText(DALPath, DALText, False)
Dim AP As New AddToProject
AP.AddToProject(GetProject, GetFolderPath, GetClassName, "Data\BLL")
AP.AddToProject(GetProject, GetFolderPath, GetClassName, "Data\DAL")
and the 2 files are added to the project folder Data/BLL & Data/DAL folders.
The files are added to the project and then im prompted for a project reload. The problem is once that process is complete. My project settings get an error
So, something is operating properly. Can anyone identify where i am going wrong?
Thanks
I am here to ask questions and learn from others. Cor Ligthert DO NOT REPLY TO ANY OF MY POSTS!!
Continue reading...