MSBuild错误CS2001源文件找不到 [英] MSBuild error CS2001 source file could not be found

查看:2388
本文介绍了MSBuild错误CS2001源文件找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用MSbuild在我的一个项目上做一个命令行构建。解决方案和项目在VS2012中构建良好,但当我执行包含

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:

这个项目是一个MVC 4项目。 MVC有一个选项,您可以在项目文件中将构建剃刀视图作为编译过程的一部分,表面上,所以你可以捕获通常是构建时的运行时错误。

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.

这个特性没有得到特别好的支持,当你从命令行构建时,它开始在奇怪的地方寻找东西,因为它正在做这些中间构建。这些视图是在temp目录中构建的,然后它试图从项目目录中复制它,然后一切都会崩溃。

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.

此外,我们需要知道解决方案dir一些后期构建事件,但这将是与大多数人无关。我们还构建一个包,然后直接部署,使它更容易将东西复制到各种需要去的地方。构建为一个包也可以正确解决项目可能具有的所有解决方案引用,用于更复杂的项目。

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;

这篇关于MSBuild错误CS2001源文件找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆