novotnyllc / MSBuildSdkExtras

Extra properties for MSBuild SDK projects
MIT License
347 stars 42 forks source link

Add workarounds for ClickOnce (ResolveAssemblyReferences) related issues #58

Closed Daniel-Svensson closed 6 years ago

Daniel-Svensson commented 6 years ago

Would you be interested in adding workarounds for issues with publishing (clickonce) in the build process which are caused by how sdk style projects and PackageReference incorrectly sets "Private=True" for references?

Issues:

Workaround for both of these issues can be done in the project file by adding the following code at the end so I hope it should be easy to add to the extras sdk, but I am very unsure about where to put it so that is why I put it here and dont post a PR.

The following code manually create "PublishFile" items for items which would otherwise be classified incorrectly.

<Target Name="EnsureNetstandardFilesAreIncludedInClickOnce" BeforeTargets="_DeploymentComputeClickOnceManifestInfo">
    <Message Text="Adding netstandard files to ClickOnce" />
    <ItemGroup>
      <PublishFile Include="@(_NETStandardLibraryNETFrameworkLib->'%(FileName)')" KeepMetadata="None">
        <PublishState>Include</PublishState>
        <FileType>Assembly</FileType>
      </PublishFile>
    </ItemGroup>
    <!-- Consider using ReferenceCopyLocalPaths instead, if we are missing files -->
    <Message Text="Adding nuget files to ClickOnce" />
    <ItemGroup>
      <PublishFile Include="@(ReferencePath->'%(FileName)')" Condition=" '%(ReferencePath.NuGetSourceType)' == 'Package' and '%(ReferencePath.NuGetIsFrameworkReference)' != 'true'" KeepMetadata="None">
        <PublishState>Include</PublishState>
        <FileType>Assembly</FileType>
      </PublishFile>
    </ItemGroup>

    <Message Text="Adding Private True references to ClickOnce" />
    <ItemGroup>
      <PublishFile Include="@(ReferencePath->'%(FileName)')" Condition="'%(ReferencePath.Private)' == 'True'" KeepMetadata="None">
        <PublishState>Include</PublishState>
        <FileType>Assembly</FileType>
      </PublishFile>
    </ItemGroup>
    </Target>
clairernovotny commented 6 years ago

Thanks! I can certainly look to add a workaround for ClickOnce. Before I do, have you checked with the latest 15.7 preview 4 build that came out yesterday? I think there may been some fixes in this area.

Daniel-Svensson commented 6 years ago

No i haven't tried that version. Still running last 15.6 build. But I just went through all issues closed in the msbuild repo for the last month and none if them sounded like it would/could fix any of the issues

Daniel-Svensson commented 6 years ago

The same issue exist for 15.7 , but in addition Exclude="netfx.force.conflicts" must be added to the first netstandard workaround

techcap commented 6 years ago

Still doesn't work for 15.7.5.

clairernovotny commented 6 years ago

I saw a report on the main ClickOnce issue thread that it appears to be fixed in 15.8 preview 5.

techcap commented 6 years ago

When I used this workaround, compile error is solved. But nuget ref dll instead of lib dll is published. In project build output, lib dll is generated.

Testing procedure

  1. Create wpf application
  2. Add nuget reference of System.Buffers v4.5.
  3. ClickOnce publish. It generates proper lib dll of System.Buffers.dll.deploy.
  4. Migrate packages.config to PakcageReference
  5. Apply this workaround
  6. ClickOnce publish, It generates wrong ref dll of System.Buffers.dll.deploy.
Daniel-Svensson commented 6 years ago

I have a fix for refs paths at work which I forgot to update this issue with.

I won't have access to the fix for a few weeks in the mean time maybe the official suggested workarounds at https://github.com/dotnet/standard/issues/529 for netstandard references can solve some of the issues .

Daniel-Svensson commented 6 years ago

@onovotny @techcap the issues seems to be resolved in 15.8

Be ware of issues in 15.8.1 if any project include localized Resources https://developercommunity.visualstudio.com/content/problem/317922/wrong-path-to-resource-in-manifest-for-clickonce-a.html