Force Visual Studio to rebuild on Start Debugging
Asked Answered
P

1

0

This is very different compared to How to tell visual studio to rebuild every time I make a change?

The issue is that I have modified a csproj that is not referenced a project (because it's run-time dependency).

So for example, in my csproj file I have:

<Import Project=".\UnreferencedProjects-Developer.targets" />

In my .targets file, I have:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="BuildDependencyForDevelopers" AfterTargets="Build">
    <Message Text="========================================" />
    <Message Text="Developer Building Unreferenced Projects" />
    <Message Text="========================================" />
    <!--MSBuild Projects="$(ProjectToBuild)"-->
    <MSBuild Projects="../OtherProject/OtherProject.csproj">
      <Output ItemName="ProjectOutputs" TaskParameter="TargetOutputs"/>
    </MSBuild>
    <Message Text="@(ProjectOutputs)"/>
    <Message Text="=======================================" />
    <Message Text="Developer Copying Unreferenced Projects" />
    <Message Text="=======================================" />
    <Copy SourceFiles="$(ProjectDir)\..\OtherProject\bin\$(Configuration)\OtherProject.dll" DestinationFolder="$(OutDir)" ContinueOnError="true"/>
    <Copy SourceFiles="$(ProjectDir)\..\OtherProject\bin\$(Configuration)\OtherProject.pdb" DestinationFolder="$(OutDir)" ContinueOnError="true"/>
    <Message Text="=============================================" />
    <Message Text="Developer Finished with Unreferenced Projects" />
    <Message Text="=============================================" />
  </Target>
</Project>

The issue is that the .targets. file seems to only execute on a manual build/rebuild, and not on a Start Debugging.

All Configurations are set to Build. Options -> Project and Solutions -> Build and Run -> On Run, when projects are out of date: Always build.

I think the issue is that because the project is unreferenced, when I Start Debugging there are no out of date projects so it launches without a build/rebuild. How do I force it to literally always (re)build.

Phonologist answered 14/3, 2016 at 19:30 Comment(2)
Does this answer your question? Why doesn't F5 rebuild project before execution in Visual Studio?Haft
@Haft No. I even mentioned your linked answers answer in my question.Phonologist
B
9

Add to project:

<PropertyGroup><DisableFastUpToDateCheck>true</DisableFastUpToDateCheck></PropertyGroup>

Keyword here is "fast update check": Visual Studio uses it when you debug to avoid even starting up msbuild.

Related topic: MSBuild Target that always runs when clicking build in VS2013

Background info: https://msdn.microsoft.com/library/ms171468%28v=vs.110%29.aspx

If you start debugging in the in Visual Studio UI (either by choosing the F5 key or by choosing Debug, Start Debugging on the menu bar), the build process uses a fast update check to improve performance. In some cases where customized builds create files that get built in turn, the fast update check does not correctly identify the changed files. Projects that need more thorough update checks can turn off the fast checking by setting the environment variable DISABLEFASTUPTODATECHECK=1. Alternatively, projects can set this as an MSBuild property in the project or in a file the project imports.

Bicipital answered 15/3, 2016 at 6:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.