0

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.

Tarta
  • 1,729
  • 1
  • 29
  • 63
  • Did you Google for `C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found`? – mjwills Jul 28 '20 at 13:42
  • @mjwills yeah but from what I understand many of the reported problems happen at compilation time while mine is at runtime.. – Tarta Jul 28 '20 at 13:45

1 Answers1

0

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

Mahyar Mottaghi Zadeh
  • 1,178
  • 6
  • 18
  • 31
Martin
  • 1
  • 1