Reputation: 2063
I am using t4 templates to generate code.
One of the parts I am generating is sql code and I would like to add it to a SQL DB project in my solution.
What I tried so far is:
var p = new Project($@"..\..\..\{projectName}\{projectName}.sqlproj");
p.AddItem("Compile", $@"..\..\..\{projectName}\{folderName}\{fileName}");
p.Save();
However it fails on the new Project part already. Error:
Microsoft.Build.Exceptions.InvalidProjectFileException: 'The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.
However the .sqlproj is there. What I am trying to achieve is not only adding the file itself to the project, but make it included as well in the build.
Is there another way or am I doing something wrong? I am using .net Framework.
Upvotes: 0
Views: 906
Reputation: 1
If you want just add a file, try the overloaded constructor with IgnoreMissingImport flag, it worked for me:
Project p = new Project($@"..\..\..\{projectName}\{projectName}.sqlproj", null, null, new ProjectCollection(), ProjectLoadSettings.IgnoreMissingImports);
You can find more information about Project Constructors here
Upvotes: 0