Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different behavior of VS 2019 build and dotnet msbuild #15654

Open
codingdave opened this issue Feb 3, 2021 · 4 comments
Open

different behavior of VS 2019 build and dotnet msbuild #15654

codingdave opened this issue Feb 3, 2021 · 4 comments

Comments

@codingdave
Copy link

Description

From what I understand dotnet msbuild shall behave identical to building with Visual Studio (I have not read that anywhere and such my premises might be wrong).

My expectation is the behavior of Visual Studio: That the PostBuildEvent is not called if the output is not updated.

When I compile my sample from Visual Studio 2019 16.8.4 this is the output

Build started...
1>------ Build started: Project: testLibrary, Configuration: Debug Any CPU ------
1>testLibrary -> D:\Projects\msbuildTest\testLibrary\bin\Debug\net5.0\testLibrary.dll
1>"**************************** Post-build testLibrary ****************************"
2>------ Build started: Project: testConsoleApplication, Configuration: Debug Any CPU ------
2>testConsoleApplication -> D:\Projects\msbuildTest\testConsoleApplication\bin\Debug\net5.0\testConsoleApplication.dll
2>"**************************** Post-build testConsoleApplication ****************************"
========== Build: 2 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

The second run then yields:

Build started...
========== Build: 0 succeeded, 0 failed, 2 up-to-date, 0 skipped ==========

When I compile it using dotnet build

PS D:\Projects\msbuildTest> dotnet build

Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.   

  Determining projects to restore...
  Restored D:\Projects\msbuildTest\testConsoleApplication\testConsoleApplication.csproj (in 77 ms).
  Restored D:\Projects\msbuildTest\testLibrary\testLibrary.csproj (in 76 ms).
  testLibrary -> D:\Projects\msbuildTest\testLibrary\bin\Debug\net5.0\testLibrary.dll
  "**************************** Post-build testLibrary ****************************"
  testConsoleApplication -> D:\Projects\msbuildTest\testConsoleApplication\bin\Debug\net5.0\testConsoleApplication.dll
  "**************************** Post-build testConsoleApplication ****************************"

Build succeeded.        
    0 Warning(s)        
    0 Error(s)

Time Elapsed 00:00:07.38

The second run then yields:

PS D:\Projects\msbuildTest> dotnet build

Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.   

  Determining projects to restore...
  All projects are up-to-date for restore.
  testLibrary -> D:\Projects\msbuildTest\testLibrary\bin\Debug\net5.0\testLibrary.dll
  "**************************** Post-build testLibrary ****************************"
  testConsoleApplication -> D:\Projects\msbuildTest\testConsoleApplication\bin\Debug\net5.0\testConsoleApplication.dll
  "**************************** Post-build testConsoleApplication ****************************"

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.34

When I compile it using dotnet msbuild

PS D:\Projects\msbuildTest> dotnet msbuild

Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  testLibrary -> D:\Projects\msbuildTest\testLibrary\bin\Debug\net5.0\testLibrary.dll
  "**************************** Post-build testLibrary ****************************"
  testConsoleApplication -> D:\Projects\msbuildTest\testConsoleApplication\bin\Debug\net5.0\testConsoleApplication.dll
  "**************************** Post-build testConsoleApplication ****************************"

The second run then yields:

PS D:\Projects\msbuildTest> dotnet msbuild

Microsoft (R) Build Engine version 16.8.3+39993bd9d for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  testLibrary -> D:\Projects\msbuildTest\testLibrary\bin\Debug\net5.0\testLibrary.dll
  "**************************** Post-build testLibrary ****************************"
  testConsoleApplication -> D:\Projects\msbuildTest\testConsoleApplication\bin\Debug\net5.0\testConsoleApplication.dll
  "**************************** Post-build testConsoleApplication ****************************"

So what we can observe here is that dotnet build and dotnet msbuild both call the PostBuildEvent even when the output was not updated but Visual Studio does that only when the output was updated.

Configuration

  • dotnet: 5.0.102
  • Visual Studio 2019 16.8.4

Additional Information

I have added the minimal sample msbuildTest.zip I have been using for the results given above.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@jkotas jkotas transferred this issue from dotnet/runtime Feb 3, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged Request triage from a team member label Feb 3, 2021
@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@sfoslund
Copy link
Member

sfoslund commented Feb 8, 2021

VS build and dotnet msbuild behavior will not always match exactly, so it sounds like this is expected. It looks like VS detects that no files have been changed and does not run the build the second time (meaning it skips the post build event too). Since that logic does not exist on the command line, when you run 'dotnet msbuild' or 'dotnet build' the build and the post build event are both rerun the second time.

Is there a specific difference here that you think might be a bug or are we okay to close this?

@sfoslund sfoslund removed the untriaged Request triage from a team member label Feb 8, 2021
@sfoslund sfoslund added this to the Discussion milestone Feb 8, 2021
@sfoslund sfoslund removed their assignment Feb 8, 2021
@codingdave
Copy link
Author

codingdave commented Feb 9, 2021

Hi @sfoslund, thanks for your reply.

It looks like dotnet cannot deal with incremental builds. I am using the postbuild event in this example only to showcase that the incremental build does not seem to work.

I am migrating a bigger non-sdk style project that was built with VS 2019 to the net sdk-style projects and dotnet. I expect that I can end up with a build flow similar to my old (VS 2019) feature wise.

One important aspect of a build system for me is incremental building and being able to hook into build events. Imagine I want to recompile an assembly every time the git revision has changed (using e.g. gitversion) or I want to generate a set of files every time a dependent project has changed (executing "$(TargetPath)" in the post-build event). It does not make sense to execute these tasks when the dependencies did not change.

This does work fine with VS 2019, thats why I assumed it should also work with dotnet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants