dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.21k stars 1.35k forks source link

Wrong AppConfig property value (Set Property: AppConfig) - prepends .csproj name #1873

Closed jflsitecore closed 7 years ago

jflsitecore commented 7 years ago

Trying to run a build using msbuild 15. It fails on trying to copy the .config file from the obj\debug\net452 folder but for some reason it's adding the full .csproj name

so code.exe.config is resolved as Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config

08:13:09.957     1>Target "GenerateBindingRedirectsUpdateAppConfig: (TargetId:127)" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64\Microsoft.Common.CurrentVersion.targets" from project "C:\Projects\Sitecore.Demo.Retail\src\Foundation\Commerce\Engine\code\Sitecore.Foundation.Commerce.Engine.csproj" (target "ResolveReferences" depends on it):
                   Set Property: AppConfig=obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config
                   Added Item(s): 
                       AppConfigWithTargetPath=
                           obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config
                                   TargetPath=code.exe.config

Here is the Sitecore.Foundation.Commerce.Engine.csproj content:

<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk.Web" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <TargetFramework>net452</TargetFramework>
    <PreserveCompilationContext>false</PreserveCompilationContext>
    <AssemblyName>code</AssemblyName>
    <OutputType>Exe</OutputType>
    <PackageId>code</PackageId>
  </PropertyGroup>

  <!--<ItemGroup>
    <None Update="wwwroot\**\*">
      <CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
    </None>
  </ItemGroup>-->

  <ItemGroup>
    <ProjectReference Include="..\..\legacyCommerce\Plugin.Sample.Habitat\Plugin.Sample.Habitat.csproj" />
    <ProjectReference Include="..\..\legacyCommerce\Plugin.Sample.Payments.Braintree\Plugin.Sample.Payments.Braintree.csproj" />
    <ProjectReference Include="..\..\legacyCommerce\Sitecore.Commerce.Plugin.AdventureWorks\Sitecore.Commerce.Plugin.AdventureWorks.csproj" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Diagnostics" Version="1.0.2" />
    <PackageReference Include="Microsoft.AspNetCore.Server.IISIntegration" Version="1.0.2" />
    <PackageReference Include="Microsoft.AspNetCore.Server.Kestrel" Version="1.0.3" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.0.2" />
    <PackageReference Include="Microsoft.AspNetCore.OData" Version="6.0.0-alpha1-rtm-121216" />
    <PackageReference Include="Microsoft.ApplicationInsights" Version="2.1.0" />
    <PackageReference Include="Serilog" Version="2.4.0" />
    <PackageReference Include="Sitecore.Commerce.Core" Version="1.0.2301" />
    <PackageReference Include="Serilog.Sinks.Literate" Version="2.1.0" />
    <PackageReference Include="Serilog.Sinks.RollingFile" Version="3.3.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.1" />
    <PackageReference Include="Serilog.Extensions.Logging" Version="1.4.0" />
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="1.0.2" />
    <PackageReference Include="Sitecore.Commerce.Provider.FileSystem" Version="1.0.2301" />
    <PackageReference Include="Sitecore.Framework.Rules" Version="1.1.12" />
    <PackageReference Include="Sitecore.Framework.Rules.Serialization" Version="1.1.12" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.1" />
    <PackageReference Include="Sitecore.Framework.Diagnostics" Version="1.1.4" />
  </ItemGroup>

  <ItemGroup Condition=" '$(TargetFramework)' == 'net452' ">
    <Reference Include="System" />
    <Reference Include="Microsoft.CSharp" />
  </ItemGroup>

</Project>
rainersigwald commented 7 years ago

What is the actual error that you're seeing? With your project (removing project and package references I didn't have), I see successful builds with

_CopyAppConfigFile:
  Copying file from "obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config" to "bin\Debug\net452\code.exe.config".

Are you just running into a MAX_PATH problem like https://github.com/Microsoft/msbuild/issues/1786?

jflsitecore commented 7 years ago

I apologize for leaving the most important part out.

File not found is what I'm getting because it's resolving the config file as Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config as opposed to code.exe.config as it seemingly should be as that's the assemblyName.

08:13:11.290 1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.Publish.targets(128,5): error MSB3030: Could not copy the file "obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config" because it was not found.

code.exe.config exists in obj\debug\net452 but Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config does not

rainersigwald commented 7 years ago

That file should be created in the GenerateBindingRedirects target (and is on my machine). Can you build with a diagnostic log (msbuild /flp:v=diag) and share the resultant msbuild.log?

From my repro:

Target "GenerateBindingRedirects: (TargetId:36)" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\bin\Microsoft.Common.CurrentVersion.targets" from project "S:\work\msb1873\Sitecore.Foundation.Commerce.Engine.csproj" (target "ResolveReferences" depends on it):
Building target "GenerateBindingRedirects" completely.
Output file "obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config" does not exist.
Using "GenerateBindingRedirects" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "GenerateBindingRedirects" (TaskId:16)
...
  Output Item(s): 
      FileWrites=
          obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config
                  OriginalItemSpec=app.config
                  TargetPath=code.exe.config (TaskId:16)
Done executing task "GenerateBindingRedirects". (TaskId:16)
jflsitecore commented 7 years ago

Here is the log

build-log.zip

jflsitecore commented 7 years ago

@rainersigwald any chance you were able to glance at my log? I've been sitting here pressing F5 for over two hours. Kidding of course but this one is a blocker for me (aren't they always?).

Thanks a bunch!

jflsitecore commented 7 years ago

Continuing to work on this, I changed the AssemblyName in the project properties from code to Sitecore.Foundation.Commerce.Engine and now the "file not found" is looking for:

Sitecore.Foundation.Commerce.Engine.csproj.Sitecore.Foundation.Commerce.Engine.exe.config

rainersigwald commented 7 years ago

@jflsitecore To set expectations, issues filed in this repo aren't under an SLA and we don't guarantee that we'll help you investigate in any kind of timely fashion.

jflsitecore commented 7 years ago

I certainly wasn't "expecting" a quick response. I was gently asking. At this point I imagine we'll probably look at opening an incident for this.

Appreciate you looking at this in the first place. If nobody had a clue by the morning I'll create a request.

Cheers!

Sent from my iPhone

On Mar 16, 2017, at 15:02, Rainer Sigwald notifications@github.com<mailto:notifications@github.com> wrote:

@jflsitecorehttps://github.com/jflsitecore To set expectations, issues filed in this repo aren't under an SLA and we don't guarantee that we'll help you investigate in any kind of timely fashion.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Microsoft/msbuild/issues/1873#issuecomment-287159107, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AY24vgXYzA1gXe-1gzWUh3MAwBFZJzPVks5rmYcsgaJpZM4MfQIV.

This message and its attachments are for the designated recipient only and may contain proprietary or otherwise confidential information. If you have received this message in error, please notify the sender immediately and delete the original. Any other sharing, copying or use of this message by you is strictly prohibited.

rainersigwald commented 7 years ago

This is happening because GenerateBindingRedirectsUpdateAppConfig is running, which specifies that the app config points to _GenerateBindingRedirectsIntermediateAppConfig, which is the filename that is later complained about being missing.

08:13:09.957     1>Target "GenerateBindingRedirectsUpdateAppConfig: (TargetId:127)" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64\Microsoft.Common.CurrentVersion.targets" from project "C:\Projects\Sitecore.Demo.Retail\src\Foundation\Commerce\Engine\code\Sitecore.Foundation.Commerce.Engine.csproj" (target "ResolveReferences" depends on it):
                   Set Property: AppConfig=obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config
                   Added Item(s): 
                       AppConfigWithTargetPath=
                           obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config
                                   TargetPath=code.exe.config

That target is condiditoned on Exists('$(_GenerateBindingRedirectsIntermediateAppConfig)'). On my machine, that file exists and is generated by the GenerateBindingRedirects target, which produces it because it gets a list of SuggestedBindingRedirects from ResolveAssemblyReferences. In your log it apparently exists (since that Exists() condition fires) but then doesn't get produced later. That's confusing.

One of the redirected assemblies on my machine is Microsoft.Extensions.Configuration. RAR logs this on my machine:

  Unified primary reference "Microsoft.Extensions.Configuration, Version=1.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60". (TaskId:15)
      Using this version instead of original version "1.0.0.0" in "C:\Users\raines\.nuget\packages\microsoft.applicationinsights.aspnetcore\1.0.2\lib\net451\Microsoft.ApplicationInsights.AspNetCore.dll" because AutoUnify is 'true'. (TaskId:15)
      Resolved file path is "C:\Users\raines\.nuget\packages\microsoft.extensions.configuration\1.0.2\lib\netstandard1.1\Microsoft.Extensions.Configuration.dll". (TaskId:15)
      Reference found at search path location "{RawFileName}". (TaskId:15)
      Found related file "C:\Users\raines\.nuget\packages\microsoft.extensions.configuration\1.0.2\lib\netstandard1.1\Microsoft.Extensions.Configuration.xml". (TaskId:15)
      This reference is not "CopyLocal" because at least one source item had "Private" set to "false" and no source items had "Private" set to "true". (TaskId:15)
      The ImageRuntimeVersion for this reference is "v4.0.30319". (TaskId:15)

In your log the equivalent is

Primary reference "Microsoft.Extensions.Configuration, Version=1.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60". (TaskId:71)
    Resolved file path is "C:\Users\jfl\.nuget\packages\microsoft.extensions.configuration\1.0.2\lib\netstandard1.1\Microsoft.Extensions.Configuration.dll". (TaskId:71)
    Reference found at search path location "{RawFileName}". (TaskId:71)
    Found related file "C:\Users\jfl\.nuget\packages\microsoft.extensions.configuration\1.0.2\lib\netstandard1.1\Microsoft.Extensions.Configuration.xml". (TaskId:71)
    This reference is not "CopyLocal" because at least one source item had "Private" set to "false" and no source items had "Private" set to "true". (TaskId:71)
    The ImageRuntimeVersion for this reference is "v4.0.30319". (TaskId:71)

That is odd. Can you ildasm or similar and confirm that C:\Users\jfl\.nuget\packages\microsoft.applicationinsights.aspnetcore\1.0.2\lib\net451\Microsoft.ApplicationInsights.AspNetCore.dll has a reference to Microsoft.Extensions.Configuration, Version=1.0.0.0?

Or maybe try deleting your NuGet package cache and trying again--perhaps something is corrupt there?

jflsitecore commented 7 years ago

I'll take a peek first thing in the morning ~6am eastern!

Sent from my iPhone

On Mar 16, 2017, at 15:27, Rainer Sigwald notifications@github.com<mailto:notifications@github.com> wrote:

This is happening because GenerateBindingRedirectsUpdateAppConfig is running, which specifies that the app config points to _GenerateBindingRedirectsIntermediateAppConfig, which is the filename that is later complained about being missing.

08:13:09.957 1>Target "GenerateBindingRedirectsUpdateAppConfig: (TargetId:127)" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\amd64\Microsoft.Common.CurrentVersion.targets" from project "C:\Projects\Sitecore.Demo.Retail\src\Foundation\Commerce\Engine\code\Sitecore.Foundation.Commerce.Engine.csproj" (target "ResolveReferences" depends on it): Set Property: AppConfig=obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config Added Item(s): AppConfigWithTargetPath= obj\Debug\net452\Sitecore.Foundation.Commerce.Engine.csproj.code.exe.config TargetPath=code.exe.config

That target is condiditonedhttps://github.com/Microsoft/msbuild/blob/8ec190f8bb2219d150e5c19bf72e1df89c6e638c/src/Tasks/Microsoft.Common.CurrentVersion.targets#L2065 on Exists('$(_GenerateBindingRedirectsIntermediateAppConfig)'). On my machine, that file exists and is generated by the GenerateBindingRedirects target, which produces it because it gets a list of SuggestedBindingRedirects from ResolveAssemblyReferences. In your log it apparently exists (since that Exists() condition fires) but then doesn't get produced later. That's confusing.

One of the redirected assemblies on my machine is Microsoft.Extensions.Configuration. RAR logs this on my machine:

Unified primary reference "Microsoft.Extensions.Configuration, Version=1.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60". (TaskId:15) Using this version instead of original version "1.0.0.0" in "C:\Users\raines.nuget\packages\microsoft.applicationinsights.aspnetcore\1.0.2\lib\net451\Microsoft.ApplicationInsights.AspNetCore.dll" because AutoUnify is 'true'. (TaskId:15) Resolved file path is "C:\Users\raines.nuget\packages\microsoft.extensions.configuration\1.0.2\lib\netstandard1.1\Microsoft.Extensions.Configuration.dll". (TaskId:15) Reference found at search path location "{RawFileName}". (TaskId:15) Found related file "C:\Users\raines.nuget\packages\microsoft.extensions.configuration\1.0.2\lib\netstandard1.1\Microsoft.Extensions.Configuration.xml". (TaskId:15) This reference is not "CopyLocal" because at least one source item had "Private" set to "false" and no source items had "Private" set to "true". (TaskId:15) The ImageRuntimeVersion for this reference is "v4.0.30319". (TaskId:15)

In your log the equivalent is

Primary reference "Microsoft.Extensions.Configuration, Version=1.0.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60". (TaskId:71) Resolved file path is "C:\Users\jfl.nuget\packages\microsoft.extensions.configuration\1.0.2\lib\netstandard1.1\Microsoft.Extensions.Configuration.dll". (TaskId:71) Reference found at search path location "{RawFileName}". (TaskId:71) Found related file "C:\Users\jfl.nuget\packages\microsoft.extensions.configuration\1.0.2\lib\netstandard1.1\Microsoft.Extensions.Configuration.xml". (TaskId:71) This reference is not "CopyLocal" because at least one source item had "Private" set to "false" and no source items had "Private" set to "true". (TaskId:71) The ImageRuntimeVersion for this reference is "v4.0.30319". (TaskId:71)

That is odd. Can you ildasm or similar and confirm that C:\Users\jfl.nuget\packages\microsoft.applicationinsights.aspnetcore\1.0.2\lib\net451\Microsoft.ApplicationInsights.AspNetCore.dll has a reference to Microsoft.Extensions.Configuration, Version=1.0.0.0?

Or maybe try deleting your NuGet package cache and trying again--perhaps something is corrupt there?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Microsoft/msbuild/issues/1873#issuecomment-287165698, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AY24vo0m7rWISpbFMXO4qyu-CW7B3VAdks5rmY0tgaJpZM4MfQIV.

This message and its attachments are for the designated recipient only and may contain proprietary or otherwise confidential information. If you have received this message in error, please notify the sender immediately and delete the original. Any other sharing, copying or use of this message by you is strictly prohibited.

jflsitecore commented 7 years ago

@rainersigwald

I can confirm that C:\Users\jfl.nuget\packages\microsoft.applicationinsights.aspnetcore\1.0.2\lib\net451\Microsoft.ApplicationInsights.AspNetCore.dll has a reference to Microsoft.Extensions.Configuration v 1.0.0.0

Forgive my lack of experience with this area.

I see that Microsoft.Extensions.Configuration has a version 1.0.0 and 1.0.2 in my packages cache (I initially cleared it and restored packages). Inside both of those folders they only have netstandard1.1 folder in the lib folder. Not sure if that means anything since the applicationinsights is net452?

jflsitecore commented 7 years ago
C:\Users\jfl\.nuget\packages\microsoft.extensions.configuration>dir 1.0.0\lib
 Volume in drive C is Windows
 Volume Serial Number is 3A27-4900

 Directory of C:\Users\jfl\.nuget\packages\microsoft.extensions.configuration\1.0.0\lib

03/17/2017  05:56 AM    <DIR>          .
03/17/2017  05:56 AM    <DIR>          ..
03/17/2017  05:56 AM    <DIR>          netstandard1.1
               0 File(s)              0 bytes
               3 Dir(s)  230,475,849,728 bytes free

C:\Users\jfl\.nuget\packages\microsoft.extensions.configuration>dir 1.0.2\lib
 Volume in drive C is Windows
 Volume Serial Number is 3A27-4900

 Directory of C:\Users\jfl\.nuget\packages\microsoft.extensions.configuration\1.0.2\lib

03/17/2017  05:56 AM    <DIR>          .
03/17/2017  05:56 AM    <DIR>          ..
03/17/2017  05:56 AM    <DIR>          netstandard1.1
               0 File(s)              0 bytes
               3 Dir(s)  230,475,849,728 bytes free

C:\Users\jfl\.nuget\packages\microsoft.extensions.configuration>
rainersigwald commented 7 years ago

One possible mitigation would be to drop an empty app.config file next to the project and let it get piped through the system that way.

jflsitecore commented 7 years ago

My colleague is having an unrelated VS 2015 / .NET Core issue. He’s trying to re-create the projects/solution from scratch. I’ll try your suggestion and at the same time we’ll see if his approach provides us with a working build!

Thanks for the follow-up.

From: Rainer Sigwald [mailto:notifications@github.com] Sent: Friday, March 17, 2017 2:30 PM To: Microsoft/msbuild msbuild@noreply.github.com Cc: Jean-François Larente jfl@sitecore.net; Mention mention@noreply.github.com Subject: Re: [Microsoft/msbuild] Wrong AppConfig property value (Set Property: AppConfig) - prepends .csproj name (#1873)

One possible mitigation would be to drop an empty app.config file next to the project and let it get piped through the system that way.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Microsoft/msbuild/issues/1873#issuecomment-287435790, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AY24vh9qZp6c6mj_UL9CTO0m_d5HNWFUks5rmtEzgaJpZM4MfQIV.

This message and its attachments are for the designated recipient only and may contain proprietary or otherwise confidential information. If you have received this message in error, please notify the sender immediately and delete the original. Any other sharing, copying or use of this message by you is strictly prohibited.

AndyGerlicher commented 7 years ago

Team Triage: Closing this for now. Please followup if you reproduce the problem.