NuGet / Home

Repo for NuGet Client issues
Other
1.5k stars 252 forks source link

.NET Core projects supporting portable profiles are suddenly failing with FileNotFoundException: File not found: '*.pri' #5021

Closed AArnott closed 7 years ago

AArnott commented 7 years ago

On completely different projects on appveyor I'm suddenly seeing PackTask failures as shown below. All these are open source projects so you can follow the links to the source code if you want.

Code-generation: Good Bad vs-validation: Good Bad

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(104,5): error MSB4018: The "PackTask" task failed unexpectedly. [C:\projects\codegeneration-roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(104,5): error MSB4018: System.IO.FileNotFoundException: File not found: 'C:\projects\codegeneration-roslyn\bin\CodeGeneration.Roslyn.Attributes\Release\portable-net40+win8+wpa81\CodeGeneration.Roslyn.Attributes.pri'. [C:\projects\codegeneration-roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(104,5): error MSB4018:    at NuGet.Packaging.PackageBuilder.AddFiles(String basePath, String source, String destination, String exclude) [C:\projects\codegeneration-roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(104,5): error MSB4018:    at NuGet.Packaging.PackageBuilder.PopulateFiles(String basePath, IEnumerable`1 files) [C:\projects\codegeneration-roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(104,5): error MSB4018:    at NuGet.Commands.MSBuildProjectFactory.CreateBuilder(String basePath, NuGetVersion version, String suffix, Boolean buildIfNeeded, PackageBuilder builder) [C:\projects\codegeneration-roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(104,5): error MSB4018:    at NuGet.Commands.PackCommandRunner.BuildFromProjectFile(String path) [C:\projects\codegeneration-roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(104,5): error MSB4018:    at NuGet.Commands.PackCommandRunner.BuildPackage(String path) [C:\projects\codegeneration-roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(104,5): error MSB4018:    at NuGet.Commands.PackCommandRunner.BuildPackage() [C:\projects\codegeneration-roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(104,5): error MSB4018:    at NuGet.Build.Tasks.Pack.PackTaskLogic.BuildPackage(PackCommandRunner runner) [C:\projects\codegeneration-roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(104,5): error MSB4018:    at NuGet.Build.Tasks.Pack.PackTask.Execute() [C:\projects\codegeneration-roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(104,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [C:\projects\codegeneration-roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj]
C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\Sdks\NuGet.Build.Tasks.Pack\buildCrossTargeting\NuGet.Build.Tasks.Pack.targets(104,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__26.MoveNext() [C:\projects\codegeneration-roslyn\src\CodeGeneration.Roslyn.Attributes\CodeGeneration.Roslyn.Attributes.csproj]

Tip: these are not UWP projects so I wouldn't expect any .pri files.

csdahlberg commented 7 years ago

I just started seeing this in one of my NETStandard projects that includes a portable target framework. I was able to repro by creating a new NETStandard project in VS2017 and editing the .csproj to be this:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>portable-net45+win8+wp8</TargetFramework>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetFramework)' == 'portable-net45+win8+wp8'">
    <TargetFrameworkIdentifier>.NETPortable</TargetFrameworkIdentifier>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
    <TargetFrameworkProfile>Profile78</TargetFrameworkProfile>
    <NugetTargetMoniker>.NETPortable,Version=v0.0,Profile=Profile78</NugetTargetMoniker>
    <LanguageTargets>$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets</LanguageTargets>
  </PropertyGroup>

</Project>

It used to build just fine, I think up until I installed the most recent VS2017 update.

rohit21agrawal commented 7 years ago

I looked into this with the project file that @csdahlberg provided. The Pack target packs pri file if IncludeProjectPriFile is set to true, in which case, it looks at ProjectPriFullPath to see where the pri file is generated at. It turns out that msbuild does set IncludeProjectPriFile=true for this project, and set ProjectPriFullPath = D:\temp\prifilefailure\prifilefailure\bin\Debug\portable-net45+win8+wp8\prifilefailure.pri in the inner build (when TargetFramework is set).

We can make Pack more resilient by checking if file exists or not, but I think msbuild shouldn't tell us to include the pri file when it isn't putting it on disk.

CC: @AArnott

AArnott commented 7 years ago

I filed a support forum issue with AppVeyor and they concur that this is a regression in 15.1.

AArnott commented 7 years ago

Given it's related to portable profiles, @onovotny should be aware of it. Perhaps if setting <IncludeProjectPriFile>false</IncludeProjectPriFile> is a workaround it can be done in his MSBuildSdkExtras package.

rohit21agrawal commented 7 years ago

I have verified that setting <IncludeProjectPriFile>false</IncludeProjectPriFile> works.

AArnott commented 7 years ago

Thanks, @rohit21agrawal. Does anyone know where the behavior change in 15.1 came from? Did msbuild make a change? @andygerlicher?

rohit21agrawal commented 7 years ago

@AArnott the change to include Pri files in nupkg came from NuGet itself. We fixed the issue where Pri files weren't being included for cross-targeting projects which have pri files. It seemed like checking IncludeProjectPriFile was a reasonable thing to do to determine whether there was a pri file to include or not. Whether started setting this wrongly for certain frameworks in 15.1 or not is another question.

AArnott commented 7 years ago

I see the property set to true in in an Appx related MSBuild import:

    <IncludeProjectPriFile Condition="'$(IncludeProjectPriFile)' == ''">true</IncludeProjectPriFile>

This import is brought in if '$(WindowsAppContainer)' == 'true' , which is set to true by Microsoft.Portable.CurrentVersion.props.

That explains (I think) why this shows up for projects targeting portable profiles.

AArnott commented 7 years ago

I just confirmed that Microsoft.Portable.CurrentVersion.props has been setting WindowsAppContainer=true for a very long time. So this regression appears to be exclusively due to the change to nuget. Please fix this in a servicing release quickly.

clairernovotny commented 7 years ago

@AArnott do you want to submit a PR for this or should I?

AArnott commented 7 years ago

@onovotny I'm not confident about when we force either of these properties to false in the general case. Portable libraries can have PRI files, I believe. So setting it to false for all portable libraries would probably be wrong. But setting it to false if the file doesn't exist would require setting it in the middle of the build after the file would have been created if it were to be created. Or we can try to predict whether it will be created by other MSBuild items/properties in the project at evaluation time, perhaps.

So if you're confident, go for it. In the meantime, I've gone into my AppVeyor definitions and added the IncludeProjectPriFile=false environment variable in there so that it applies to all branches so I don't have to make a change to all branches that I care to build. That has unblocked me.

clairernovotny commented 7 years ago

I think the only portable profiles that can legitimately have PRI files are the ones that are WinRT-only -- like win8+wpa81, etc. I think wp8 has it too.

AArnott commented 7 years ago

Please 'thumbs up' the issue to vote for it if it impacts you. I'm trying to make the case that this warrants a fix to the servicing release of VS.

clairernovotny commented 7 years ago

@AArnott I've pushed 1.0.2 to NuGet with the attribute set for the profiles that shouldn't have Pri files https://www.nuget.org/packages/MSBuild.Sdk.Extras/1.0.2

JamesNK commented 7 years ago

I've installed VS 15.2 and I still get this error

Microsoft Visual Studio Enterprise 2017 Version 15.2 (26430.4) Release VisualStudio.15.Release/15.2.0+26430.4 Microsoft .NET Framework Version 4.6.01586

rohit21agrawal commented 7 years ago

@JamesNK the fix didn't make it into 15.2. we are still considering a servicing release, but i can't say for sure yet. You can find the workaround to apply in the meanwhile in this thread.