Error when adding view in MVC 3

2019-08-22 06:56发布

问题:

I'm using Visual Studio 2010 SP1, ASP.NET MVC 3 + tools update. When I try to add a strongly typed razor view to a controller action, VS throws an error "the templates had the following 1 error(s) when running: "

The 'ReferencedAssemblies' property cannot contain null or empty strings.
Parameter name: options
at Microsoft.VisualBasic.VBCodeGenerator.CmdArgsFromParameters(CompilerParameters options)
...

I have tried to 'clean' the project, shut down VS, reopen VS, rebuild, but I still got the same error.

Only 'empty' scaffold template works. List, details, edit, etc throw the same error.

Anybody has a solution for the error?

回答1:

I managed to fix the problem using the following steps:

  • remove reference to the library containing the model
  • clean project
  • close VS
  • reopen VS
  • rebuild project (VS throws errors)
  • re-add reference to the model library
  • rebuild project

After that, VS can successfully build the view.

EDIT

I noticed that in the process of doing the steps above, I also closed git bash console that was open on the project folder. I tried just closing the git shell, and I became able to generate views without doing the steps above. Looks like the git shell locks some files, and this causes the error when generating views.