Question

I am trying to use csc.exe from the command line to compile a .NET 1.1 .csproj project. It is failing with the following error:

MyProject.csproj(24,2046): error CS1034: Compiler limit exceeded: Line cannot exceed 2046 characters

Line 24 of the .csproj file is the PostBuildEvent attribute of the <Settings> node. I do have a lengthy post build event that exceeds 2046 characters.

This project is a legacy application that has been successfully compiling for 8+ years with no problems up until 2-6 weeks ago. (The last time it successfully compiled for me was over 6 weeks ago and then I didn't try again until a couple weeks ago, and it has been failing ever since.) I tried removing all service packs that have been installed in that time frame and it did not change the result. I am at a loss as to where to go from here.

Edit:

Using Eric J's advice below, I shortened the post build event by moving some of the commands to external .bat files and then calling them like this. Now when I try to run csc.exe, I am getting the following errors:

MyProject.csproj(491,35): error CS1010: Newline in constant

MyProject.csproj(1,1): error CS0116: A namespace does not directly contain members such as fields or methods

Line 491 of the project file is <Folder RelPath = "Xml\" />, and of course line 1 is <VisualStudioProject>.

It's like it's trying to compile my .csproj file as if it were a .cs file. Why? I am calling csc.exe like this:

csc.exe /t:library /out:transformed\Services\bin\Services.dll *.cs Cache\*.cs Settings\*.cs transformed\Services\*.cs /r:MyReference.dll /r:MySecondReference.dll /nologo /debug /define:DEBUG

Is it seeing *.cs and all of a sudden including MyProject.csproj for some reason? If so, how would I get around this?

Edit 2:

I came up with a workaround. As you can see from the command line statement above, I was compiling *.cs, which is in the same directory as the .csproj file. I had a hunch that for some reason, it was also trying to compile the project file as if it were C# code. I moved all C# source files that were in the root directory to a folder called Services, and then changed my command line statement to compile Services\*.cs. Everything works fine now.

I still don't know what caused this behavior to change recently, so if anyone has some insight I would appreciate it.

Was it helpful?

Solution

I'm not sure what would have changed to cause the post build event to fail suddenly, but you may be able to resolve the issue by creating a batch file or PowerShell script that encapsulates the lengthy event and call that script instead.

OTHER TIPS

Here is what I think has happened. In the post-build you have a Macro, something like $(TargetPath). You might changed location where your project sits and the path in $(TargetPath) became very long. Try to move your build to some simple directory, like "C:\build" and see if it will compile.

Then, if no success, try to compile your project using devenv.exe as command line, or just in visual studio. If that doesn't work, try to re-format your post-build event so that lines are shorter.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top