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

Custom build task is not called when building on solution level #3564

Closed
shhsu opened this issue Jul 30, 2018 · 4 comments
Closed

Custom build task is not called when building on solution level #3564

shhsu opened this issue Jul 30, 2018 · 4 comments
Labels

Comments

@shhsu
Copy link

shhsu commented Jul 30, 2018

Steps to reproduce

Hi:

I have created a nuget package to redistribute IIS Web Manager (currently named Microsoft.IIS.WebManager.Middleware). It's a static website. There's a build task in the nuget package that would copy the website content to a project's wwwroot directory if this nuget package is imported. The example usage was (https://github.com/shhsu/IIS.WebManager/blob/shhsu/proj/src/Microsoft.IIS.WebManager.SelfHost/Microsoft.IIS.WebManager.SelfHost.csproj)

Project file

<Project Sdk="Microsoft.NET.Sdk.Web">
  <Import Project="$(MSBuildProjectDirectory)\..\build\global.props" />
  <PropertyGroup>
    <TargetFramework>netcoreapp2.1</TargetFramework>
    <OutputPath>$(MSBuildProjectDirectory)\..\..\artifacts\WebManagerApp</OutputPath>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.App" version="2.1.0" />
    <PackageReference Include="Microsoft.IIS.WebManager.Middleware" Version="$(IISWebManagerVersion)" PrivateAssets="All" />
  </ItemGroup>
  <Target Name="PreBuild" BeforeTargets="PreBuildEvent">
    <Exec Command="dotnet restore" />
  </Target>
</Project>

Directory contents:
See https://github.com/shhsu/IIS.WebManager/tree/shhsu/proj

Command line
Edit the solution file Microsoft.IIS.WebManager.sln and re-enable building Microsoft.IIS.WebManager.SelfHost project (I disabled it because it didn't work as expected)
Call:

msbuild Microsoft.IIS.WebManager.sln

Expected behavior

The output directory WebManagerApp should contains a wwwroot directory.

Actual behavior

The wwwroot directory does not exist.

NOTE:
I was able to workaround the issue by disabling build of Microsoft.IIS.WebManager.SelfHost from solution.
And I would call
msbuild Microsoft.IIS.WebManager.sln
and build Microsoft.IIS.WebManager.Middleware first, then I would build Microsoft.IIS.WebManager.SelfHost by itself

cd Microsoft.IIS.WebManager.SelfHost
dotnet restore
msbuild

This seem to generate the result as expected, WebManagerApp has the correct content in wwwroot directory

Environment data

msbuild /version output: 15.7.177.53362

OS info:
Version 10.0.17134 Build 17134

If applicable, version of the tool that invokes MSBuild (Visual Studio, dotnet CLI, etc):

@rainersigwald
Copy link
Member

Do I understand correctly that you're both building the NuGet package and referencing it inside the same build? That definitely won't work, because project imports can't be updated after it is loaded. That means:

  1. The project is loaded (because the solution references it)
    a. At this time, there's no NuGet package to reference, so it's not imported.
  2. The PreBuild target happens, running dotnet restore
    a. The next time the project is loaded, it would see the now-restored package
  3. The build finishes, using the project from 1, because that's the build that was started.
    a. This instance of the project doesn't have your custom target.

For your scenario, I think you'd like something like dotnet/sdk#1151, but that doesn't currently exist.

@shhsu
Copy link
Author

shhsu commented Jul 31, 2018

I see. What you are describing is exactly my issue. You can close this issue as a duplicate then.

@rainersigwald
Copy link
Member

rainersigwald commented Jul 31, 2018

Duplicate of dotnet/sdk#1151

@rainersigwald rainersigwald marked this as a duplicate of dotnet/sdk#1151 Jul 31, 2018
@rainersigwald
Copy link
Member

Oh, and your workaround of building in phases sounds pretty reasonable to me, given the current state of things.

@AR-May AR-May added the triaged label Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants