Question

Here is the background, we have a solution file (a.sln) which contains 2 projects (service.csproj & client.csproj). There is another old solution file (b.sln) which contains 3 projects (service.csproj, client.csproj & test.csproj). We dont use this solution file and the test project too.

We use NANT script for compilation. Within NANT we use the <exec> task which calls the "devenv.com" to compile the solution files. I was trying to make some changes to the build script (generating the proxy for the service on the fly during build), so for this I was trying to compile the service.csproj file alone. I updated the NANT script as shown below:

<exec program="${visualstudio.install.dir}\devenv.com" commandline="&quot;${base.dir}\Service.csproj&quot; /rebuild ${config}" failonerror="true" />

But when the above line is executed it compiles (in the following order)

a. client.csproj b. service.csproj c. test.csproj

The service.csproj does not have any project references to the client and test project.

I broke my head to find what exactly is happening and how the client/test projects are getting compiled.

This is what I found, we have the following folder structure:

MyFolder -> 

    -> Service
        service.csproj
        b.sln
    -> Client
        client.csproj
    -> Test
        test.csproj
    a.sln

Since b.sln was obsolete and not used it was in the MyFolder -> Service folder (same folder as the service.csproj file). (Developers are so bad with this in my new company that they dont delete unused files and just keep renaming it as _old.)

The devnenv.com was somehow taking the project files from the b.sln file and compiling them. I deleted the b.sln file and the script compiles the service.csproj without any issues.But when the service.csproj and b.sln are in the same folder visual studio (devenv.com) tries to compile all the 3 projects mentioned within the solution file.

Anyone have any idea on what is happening?

Was it helpful?

Solution

This is the answer which I got from Microsoft about this:

When you open a project file directly, Visual Studio applies some heuristics to try to locate the parent solution file. If Visual Studio finds a solution file in the project's directory or parent directory that has a matching project name in it then Visual Studio will use that solution. Since devenv /build tries to directly reproduce the behavior of building from the UI all of these heuristics are still applied. Since the defunct b.sln contains service.csproj it is being picked up by the heuristic which can in some circumstances cause other projects in the solution to be built as well.

You can work around this issue in two ways. Either, remove the defunct solution from project's folder tree, or exec MSBuild directly to build services.csproj. MSBuild does not apply any solutions heuristics if you pass it a .*proj file.

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