MVC Scaffolding pollutes .csproj file

459 views Asked by At

When I run a custom Scaffold command in the Package Manager Console, it updates the default project's .csproj file and adds in references to all the other files in all the other projects in the solution!

Has anyone else seen this?

Is there a fix to avoid it?

The only lines in the .ps1 file that may actually do anything look like this:

Invoke-ScaffoldTemplate -Template $templateFile -Model @{ Name = $MyParam } -OutputPath $outputPath -Force:$Force 

Edit The script in the PS1 file (in the main project) manually targets the paths of the output files to be in other projects:

 $outputPath = "..\OtherProject\TargetFolder\" + $EntityName 

In the "Invoke-ScaffoldTemplate" command, I specifically removed the reference to the Project, hoping this was the problem.

1

There are 1 answers

0
Steven Sanderson On BEST ANSWER

Edit: Updated based on the additional info you added. Thanks for clarifying.

Using up-level paths like "..\OtherProject\Filename" is not the way to add files to other projects - this creates the bizarre effect you witnessed. I'll consider adding a check to throw an exception if such paths are given to Invoke-ScaffoldTemplate.

The correct way to add files to other projects is simply to pass a suitable -Project parameter to Invoke-ScaffoldTemplate. Then, the output will be added to that project, and the path will be interpreted as relative to that project.

For example,

$outputPath = "ExampleOutput"
$wroteFile = Invoke-ScaffoldTemplate -Project "OtherProject" -OutputPath $outputPath -Template $templateFile -Model @{ ... etc ... }