dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.7k stars 1.06k forks source link

Unable to execute `dotnet run` as part of the build. #14236

Closed kblok closed 3 years ago

kblok commented 4 years ago

Description

I'm trying to create a project to download a few files the real project I want to build. The idea is to create a console app to check missing files and download them if needed. I tried to do something like this on the main project:

<Target Name="Download Drivers" BeforeTargets="Build">
    <ConvertToAbsolutePath Paths="$(ProjectDir)..\tools\DriverDownloader\">
        <Output TaskParameter="AbsolutePaths" PropertyName="DriverDownloaderPath" />
    </ConvertToAbsolutePath>
    <ConvertToAbsolutePath Paths="$(ProjectDir)\Drivers\">
        <Output TaskParameter="AbsolutePaths" PropertyName="DriversPath" />
    </ConvertToAbsolutePath>
    <Exec WorkingDirectory="$(DriverDownloaderPath)" Command="dotnet run -p DriverDownloader.csproj -c Debug -- $(DriversPath)" />
</Target>

It seems that MSBuild is changing the dotnet path. So I'm getting this:

    dotnet run -p DriverDownloader.csproj -c Debug -- /Users/neo/Documents/Coding/Personal/playwright-sharp/src/PlaywrightSharp/Drivers/
    /Users/neo/Library/Caches/VisualStudio/8.0/MSBuild/2089_1/Roslyn/Microsoft.CSharp.Core.targets(70,5): error MSB4018: The "Csc" task failed unexpectedly. [/Users/neo/Documents/Coding/Personal/playwright-sharp/src/tools/DriverDownloader/DriverDownloader.csproj]
    /Users/neo/Library/Caches/VisualStudio/8.0/MSBuild/2089_1/Roslyn/Microsoft.CSharp.Core.targets(70,5): error MSB4018: System.InvalidOperationException: The "Csc" task has not registered its resources. In order to use the "TaskLoggingHelper.FormatResourceString()" method this task needs to register its resources either during construction, or via the "TaskResources" property. [/Users/neo/Documents/Coding/Personal/playwright-sharp/src/tools/DriverDownloader/DriverDownloader.csproj]
    /Users/neo/Library/Caches/VisualStudio/8.0/MSBuild/2089_1/Roslyn/Microsoft.CSharp.Core.targets(70,5): error MSB4018: at Microsoft.Build.Shared.ErrorUtilities.ThrowInvalidOperation(String resourceName, Object[] args) [/Users/neo/Documents/Coding/Personal/playwright-sharp/src/tools/DriverDownloader/DriverDownloader.csproj]
    /Users/neo/Library/Caches/VisualStudio/8.0/MSBuild/2089_1/Roslyn/Microsoft.CSharp.Core.targets(70,5): error MSB4018: at Microsoft.Build.Shared.ErrorUtilities.VerifyThrowInvalidOperation(Boolean condition, String resourceName, Object arg0) [/Users/neo/Documents/Coding/Personal/playwright-sharp/src/tools/DriverDownloader/DriverDownloader.csproj]
    /Users/neo/Library/Caches/VisualStudio/8.0/MSBuild/2089_1/Roslyn/Microsoft.CSharp.Core.targets(70,5): error MSB4018: at Microsoft.Build.Utilities.TaskLoggingHelper.FormatResourceString(String resourceName, Object[] args) [/Users/neo/Documents/Coding/Personal/playwright-sharp/src/tools/DriverDownloader/DriverDownloader.csproj]
    /Users/neo/Library/Caches/VisualStudio/8.0/MSBuild/2089_1/Roslyn/Microsoft.CSharp.Core.targets(70,5): error MSB4018: at Microsoft.Build.Utilities.TaskLoggingHelper.LogErrorWithCodeFromResources(String messageResourceName, Object[] messageArgs) [/Users/neo/Documents/Coding/Personal/playwright-sharp/src/tools/DriverDownloader/DriverDownloader.csproj]
    /Users/neo/Library/Caches/VisualStudio/8.0/MSBuild/2089_1/Roslyn/Microsoft.CSharp.Core.targets(70,5): error MSB4018: at Microsoft.CodeAnalysis.BuildTasks.ManagedCompiler.ExecuteTool(String pathToTool, String responseFileCommands, String commandLineCommands) [/Users/neo/Documents/Coding/Personal/playwright-sharp/src/tools/DriverDownloader/DriverDownloader.csproj]
    /Users/neo/Library/Caches/VisualStudio/8.0/MSBuild/2089_1/Roslyn/Microsoft.CSharp.Core.targets(70,5): error MSB4018: at Microsoft.Build.Utilities.ToolTask.Execute() [/Users/neo/Documents/Coding/Personal/playwright-sharp/src/tools/DriverDownloader/DriverDownloader.csproj]
    /Users/neo/Library/Caches/VisualStudio/8.0/MSBuild/2089_1/Roslyn/Microsoft.CSharp.Core.targets(70,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/Users/neo/Documents/Coding/Personal/playwright-sharp/src/tools/DriverDownloader/DriverDownloader.csproj]
    /Users/neo/Library/Caches/VisualStudio/8.0/MSBuild/2089_1/Roslyn/Microsoft.CSharp.Core.targets(70,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/Users/neo/Documents/Coding/Personal/playwright-sharp/src/tools/DriverDownloader/DriverDownloader.csproj]

These are the target frameworks of the library:

<TargetFrameworks>netstandard2.0;netstandard2.1</TargetFrameworks>
ghost commented 4 years ago

Tagging subscribers to this area: @safern, @viktorhofer See info in area-owners.md if you want to be subscribed.

ViktorHofer commented 4 years ago

Moving to dotnet/sdk.

dsplaisted commented 3 years ago

Can you provide a binlog, ideally both for the "inner" build that is failing, as well as the outer build that's invoking it?

/cc @am11 @kant2002

kblok commented 3 years ago

@dsplaisted I could also cook you a branch in a GitHub project. What do you think?

dsplaisted commented 3 years ago

@kblok That may also work, although if it only repros on Mac / Linux it will be a bit harder for me to repro.

kblok commented 3 years ago

Well. I just copy the same example and it's building https://github.com/microsoft/playwright-sharp/pull/985/checks?check_run_id=1364908014

Sorry about that folks.

rdasan commented 3 years ago

@kblok Not sure why this issue is closed. Is it not happening any more? I and some others are still having this issue. Please see https://github.com/dotnet/roslyn/issues/46772

kblok commented 3 years ago

@rdasan it just stopped failing...

Saibamen commented 3 years ago

@kblok - what did you do to fix this?

kblok commented 3 years ago

@Saibamen, I ended up changing the implementation. :/