Visual Studio Builds Projects Every Time I Run

前端 未结 13 958
花落未央
花落未央 2021-01-17 08:42

I have a .NET solution in Visual Studio 2010 with a bunch of projects. Up until recently, when I would run the startup project from within the IDE, projects would only buil

相关标签:
13条回答
  • 2021-01-17 09:12

    TargetFramework in .csproj vs. supportedRuntime-sku in app.config

    Just found another reason for rebuilds (at least with the new sdk-style project files, didn't try for the "old style" projects): if the TargetFramework element in the .csproj file does not match the sku-attribute of the supportedRuntime-entry in the app.config, visual studio will also rebuild the project every single time.

    For example, targeting 4.6.2 in the .csproj

    <Project Sdk="Microsoft.NET.Sdk">
      <PropertyGroup>
        <TargetFramework>net462</TargetFramework>
      </PropertyGroup>
    </Project>
    

    vs. 4.6.1 specified in app.config

    <configuration>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
        </startup>
    </configuration>
    

    will trigger a rebuild.

    0 讨论(0)
  • 2021-01-17 09:13

    There can be many reasons for MSBuild to detect a need to rebuild the project.

    In my case, I have a bunch of Pre-build events that generate code from XSD files. These causes the project to be rebuilt every time. And then other projects depending on this one will be rebuilt as well.

    0 讨论(0)
  • 2021-01-17 09:16

    My Configurations tag in a low level project (i.e. one many others depended on) had 3 entries:

     <Configurations>Debug;Release;Debug31</Configurations> 
    

    I had been experimenting with a new configuration (Debug31) and forgot about it. Removing the Debug31 configuration from the project file solved the issue. Note that the solution that contained all my projects did NOT have a Debug31 configuration. This appears to have caused this project to always be out of date, even though I was only building 'Debug' or 'Release'. Why I am not sure.

    0 讨论(0)
  • 2021-01-17 09:20

    The following worked for me. Go to Properties->Custom_Build_Step, and delete anything in "Description" field.

    0 讨论(0)
  • 2021-01-17 09:21

    Go to Tools -> Options -> Project and Solutions -> Build and Run. Look at the options there. 'Only build startup projects and dependencies on Run' should be checked.

    Additionally, you can set the build output (in the same options screen) to Detailed or Diagnostic to see if you can find any clues why the projects are built every time.

    0 讨论(0)
  • 2021-01-17 09:22

    In my experience with this issue, it was only some of the projects that rebuilt, and the rebuilds failed several times before finally succeeding. It was apparently caused by the \rootprojectdir\.vs\%projectname%\v14\.suo file being corrupted. This also caused the same projects to require rebuilding, and the same windows to be opened every single time I opened VS. Deleting the .suo file (while VS was closed) and reopening VS fixed it :)

    0 讨论(0)
提交回复
热议问题