I'm trying to do a command line build on one of my projects using MSbuild. The solution and project builds fine in VS2012, but when I execute a batch file containing
msbuild.exe project.csproj
It fails. There are so many errors I cant even scroll up past them. They are all the same error, for different files, all from other projects in the solution:
CSC : error CS2001: Source file 'folder\filename.cs' cound not be found [c:\folder\project.csproj]
I have found other questions talking about file name lengths. I tried removing every layer in the path that I could, to no avail. I find it odd that the source file path is not relative, even though the files it can't find are, indeed, from other projects. i'm at a bit of a loss here. Why does my build fail?
Alright, while this may not actually be the same problem others are seeing, I solved my specific problem:
The project in question is an MVC 4 project. MVC has an option you can enable in the project file that builds the razor views as part of the compilation process, ostensibly so you can catch what would normally be run time errors at build time.
This feature has not been particularly well supported, and when you build from command line, it starts looking for things in weird places as it is doing these intermediate builds. The views get built in temp directories, then it attempts to copy it from the project directories, then everything falls apart.
In addition, we need to know the solution dir for some post build events, but that will be irrelevant to most people. We also build to a package, then deploy directly to make it easier to copy stuff out to the various places it needs to go. Building as a package also properly resolves all the solution references the project may have, for more complex projects. I included it here for completions sake.
Here is the line that has it all working properly:
msbuild.exe /v:q projectName.csproj /t:Package /p:MvcBuildViews=false;SolutionDir=%SolutionDir%;DeployOnBuild=true
and the simple version that really fixed the problem:
msbuild.exe projectName.csproj /p:MvcBuildViews=false;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With