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

Calling publish for two TFM fails with 2.1 #1846

Closed
matkoch opened this issue Jan 8, 2018 · 13 comments
Closed

Calling publish for two TFM fails with 2.1 #1846

matkoch opened this issue Jan 8, 2018 · 13 comments

Comments

@matkoch
Copy link

matkoch commented Jan 8, 2018

I guess when I've updated VisualStudio to 15.3, it also installed SDK 2.1. In any case, the two calls:

C:\...\dotnet.exe publish C:\...\My.csproj --configuration Debug --framework netstandard2.0
C:\...\dotnet.exe publish C:\...\My.csproj --configuration Debug --framework net461

Previously worked without any issues. The project was published for both frameworks correctly (MSBuild task library). But now, I get:

C:\Program Files\dotnet\sdk\2.1.2\Microsoft.Common.CurrentVersion.targets(2041,5): warning MSB3277: Found conflicts between different versions of "System.Net.Http" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
C:\Program Files\dotnet\sdk\2.1.2\Microsoft.Common.CurrentVersion.targets(2041,5): warning MSB3277: Found conflicts between different versions of "System.IO.Compression" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
C:\Program Files\dotnet\sdk\2.1.2\Microsoft.Common.CurrentVersion.targets(2041,5): warning MSB3277: Found conflicts between different versions of "System.Runtime.InteropServices.RuntimeInformation" that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed.
error CS0433: The type 'SerializableAttribute' exists in both 'System.Runtime.Serialization.Formatters, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
error CS0433: The type 'NonSerializedAttribute' exists in both 'System.Runtime.Serialization.Formatters, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' and 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

I guess this is because of some dependency issues. When I'm cleaning the obj folder, I can correctly publish for net461 again. It's actually the bin folder I have to delete, in order to make dotnet publish work.

Adding --force doesn't solve anything. This is the most surprising thing actually.

@livarcocc
Copy link
Contributor

@joperezr can you take a look? Caused by the new packages?

@joperezr
Copy link
Member

joperezr commented Jan 9, 2018

Taking a look...

@joperezr
Copy link
Member

joperezr commented Jan 9, 2018

This initially doesn't look like something that was caused by our changes to the support package, but that said, it would be nice to have more info regarding the specific scenario. @matkoch could you please give more info regarding My.csproj? What framework does it target? What are its dependencies? Is there a repo or something I can clone to get a repro?

@matkoch
Copy link
Author

matkoch commented Jan 9, 2018

@joperezr thanks for your time.

The repository is located at https://github.com/nuke-build/nuke

After cloning and navigating to source\Nuke.CodeGeneration, you should be able to reproduce this by invoking:

dotnet publish Nuke.CodeGeneration.csproj --configuration Debug --framework netstandard2.0 --force
dotnet publish Nuke.CodeGeneration.csproj --configuration Debug --framework net461 --force

@joperezr
Copy link
Member

joperezr commented Jan 9, 2018

What version of the CLI are you using(type dotnet --version)? I just tried this on my machine and it works as expected.

image

For the record, my CLI version is: 15.5.0-preview-007044 which is the newest version.

@livarcocc
Copy link
Contributor

@joperezr The version you mention is actually a very old one. It was a nightly from when we were changing our version scheme. Please, uninstall it. The latest released one is 2.1.4, which is shipping today.

@joperezr
Copy link
Member

joperezr commented Jan 9, 2018

I see, adding a global.json to force the use of 2.1.3 does repro the issue, but I'm checking at the log and the problem doesn't seem to be related at all with the support package changes. The System.Runtime.Serialization.Formatters.dll file that is causing the conflict when building net461 target framework is the one located at bin\Debug\netstandard2.0\publish\System.Runtime.Serialization.Formatters.dll which is the output of the netstandard2.0 publish. @dsplaisted any idea why we are adding to the ReferencePath all of the contents of the bin publish output folder of netstandard2.0 when building net461 TFM?

@joperezr
Copy link
Member

joperezr commented Jan 9, 2018

Ok I see what the problem is now. The issue seems to be that in your csproj you have these two lines:

   <None Include="bin\$(Configuration)\netstandard2.0\publish\**\*.*" PackagePath="build\netstandard2.0" Pack="true" />
   <None Include="bin\$(Configuration)\net461\publish\**\*.*" PackagePath="build\net461" Pack="true" />

They are unintentionally adding to the ReferencePath all of the assemblies on those two directories. This is causing that when you try to publish for net461 but you have already published for netstandard2.0, to also reference all of the assemblies that where placed on bin\debug\netsandard2.0\publish folder, which is causing the issue. Removing those two lines solved the problem.

I'm closing the issue since this is a problem related to your project, but feel free to re-open if I missed anything.

@joperezr
Copy link
Member

joperezr commented Jan 9, 2018

Actually looks like I don't have the permissions to close it, but @livarcocc should be able to help with that 😄

@livarcocc
Copy link
Contributor

thanks for looking into this @joperezr. @matkoch I hope this addresses your issue, otherwise, like @joperezr said, make a comment and we can re-activate.

@matkoch
Copy link
Author

matkoch commented Jan 10, 2018

@joperezr first off, thanks for your help. Still I'm unsure about this. Why is this adding to ReferencePath at all? Like I said, this worked prior to installation of VS15.5 (SDK 2.1). Also it seems like common practice. Compare to how Refit is doing that. I wonder if they'll hit the same. Also, simply removing those lines isn't really an option. I could add a Condition tag, but also that doesn't seem elegant.

@joperezr
Copy link
Member

in the new SDK we add the None to the ResolveAssemblyReference task by saying that they are candidate assembly files. This will, in turn, add them to the ReferencePath which is why they are being referenced by the compiler and causing the issue. Here is a little snippet of how that code is:

...
<!-- File Microsoft.Common.CurrentVersion.targets -->
   <ResolveAssemblyReference
        Assemblies="@(Reference)"
        AssemblyFiles="@(_ResolvedProjectReferencePaths);@(_ExplicitReference)"
        TargetFrameworkDirectories="@(_ReferenceInstalledAssemblyDirectory)"
        InstalledAssemblyTables="@(InstalledAssemblyTables);@(RedistList)"
        IgnoreDefaultInstalledAssemblyTables="$(IgnoreDefaultInstalledAssemblyTables)"
        IgnoreDefaultInstalledAssemblySubsetTables="$(IgnoreInstalledAssemblySubsetTables)"
        CandidateAssemblyFiles="@(Content);@(None)"
        SearchPaths="$(AssemblySearchPaths)"
        AllowedAssemblyExtensions="$(AllowedReferenceAssemblyFileExtensions)"
        AllowedRelatedFileExtensions="$(AllowedReferenceRelatedFileExtensions)"
        TargetProcessorArchitecture="$(ProcessorArchitecture)"

...

Now whether or not that is the right thing to do is a different question, but I believe that the right or suggested way of packaging libraries like yours would be to simply call dotnet pack yourProject.csproj which would automatically create the packages for both published frameworks. I guess that @dsplaisted or @livarcocc might be a better person to ask the question of whether or not this is a bug on the sdk

@dasMulli
Copy link
Contributor

dasMulli commented Jan 10, 2018

@matkoch what you probably want is something like this (used it to pack up msbuild tasks):

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

  <PropertyGroup>
    <TargetFrameworks>netcoreapp2.0;net461</TargetFrameworks>
    <IncludeBuildOutput>false</IncludeBuildOutput>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
    <TargetsForTfmSpecificContentInPackage>$(TargetsForTfmSpecificContentInPackage);PackPublishOutput</TargetsForTfmSpecificContentInPackage>
  </PropertyGroup>

  <ItemDefinitionGroup>
    <PackageReference>
      <PrivateAssets>All</PrivateAssets>
    </PackageReference>
  </ItemDefinitionGroup>

  <ItemGroup Condition="'$(TargetFramework)' == ''">
    <!-- include .props/.targets files -->
    <None Include="build\**" Pack="true" PackagePath="build" />
    <None Include="buildCrossTargeting\**" Pack="true" PackagePath="buildCrossTargeting" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
  </ItemGroup>

  <Target Name="PreparePublishToIntermediatePaths">
    <PropertyGroup>
      <PublishDir>$(IntermediateOutputPath)TmpPackPublish\</PublishDir>
    </PropertyGroup>
    <ItemGroup>
      <_OldIntermediatePublishFiles Include="$(PublishDir)**\*.*" />
    </ItemGroup>
    <Delete Files="@(_OldIntermediatePublishFiles)" ContinueOnError="true" />
    <RemoveDir Directories="$(PublishDir)" ContinueOnError="true" Condition="Exists('$(PublishDir)')" />
    <MakeDir Directories="$(PublishDir)" Condition="!Exists('$(PublishDir)')"/>
  </Target>

  <Target Name="PackPublishOutput" DependsOnTargets="PreparePublishToIntermediatePaths;Publish">
    <ItemGroup>
      <_IntermediatePublishFiles Include="$(PublishDir)**\*.*" />
      <TfmSpecificPackageFile Include="@(_IntermediatePublishFiles)" PackagePath="build\$(TargetFramework)" />
    </ItemGroup>
  </Target>

</Project>

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

No branches or pull requests

4 participants