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

Adding assemblies to package with csproj messes up the build output #5523

Closed
Roemer opened this issue Jul 3, 2017 · 18 comments
Closed

Adding assemblies to package with csproj messes up the build output #5523

Roemer opened this issue Jul 3, 2017 · 18 comments

Comments

@Roemer
Copy link

Roemer commented Jul 3, 2017

Details about Problem

NuGet product used (NuGet.exe | VS UI | Package Manager Console | dotnet.exe): VS UI

VS version (if appropriate): 2017.3

OS version (i.e. win10 v1607 (14393.321)): Win8 / Win10

Worked before? If so, with which NuGet version: No

Detailed repro steps so we can see the same problem

Create a project with the following content:

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

  <PropertyGroup>
    <TargetFrameworks>net35;net45</TargetFrameworks>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
  </PropertyGroup>

  <ItemGroup>
    <Reference Include="Interop.UIAutomationClient" Condition="'$(TargetFramework)'=='net35'">
      <HintPath>..\libs\Interop\3.5\Interop.UIAutomationClient.dll</HintPath>
      <EmbedInteropTypes>false</EmbedInteropTypes>
      <SpecificVersion>false</SpecificVersion>
    </Reference>
    <Reference Include="Interop.UIAutomationClient" Condition="'$(TargetFramework)'=='net45'">
      <HintPath>..\libs\Interop\4.5\Interop.UIAutomationClient.dll</HintPath>
      <EmbedInteropTypes>false</EmbedInteropTypes>
      <SpecificVersion>false</SpecificVersion>
    </Reference>
  </ItemGroup>

  <ItemGroup Label="Additional nuget files">
    <None Include="..\libs\Interop\3.5\Interop.UIAutomationClient.dll" Pack="true" PackagePath="lib\net35" />
    <None Include="..\libs\Interop\4.5\Interop.UIAutomationClient.dll" Pack="true" PackagePath="lib\net45" />
  </ItemGroup>
  
</Project>

Expected result

In build output there should be the .net folders with either the 3.5 oder 4.5 version of the interop.
Also there should be a nuget package with the interop dlls.

Effective result

Because the None Include kinda adds the files to the project, the 3.5 version is copied to the output of both .net versions. The nuget package is fine.

There should be another way to add additional files to a nuget package wihout adding them to the project.

Example project

ReproTest_Del.zip

@livarcocc
Copy link

If you don't want these files in your project output, just your package, have you tried setting CopyToOutputDirectory to false as metadata to the None item? Though, to be honest, I am not sure how that will interact with Pack.

@Roemer
Copy link
Author

Roemer commented Jul 3, 2017

Unfortunately does not help. I think they are not copied by the None Inclue but because they are referenced by the project and this seems to favor the None Includes to the HintPath of the Reference.

@Roemer
Copy link
Author

Roemer commented Jul 27, 2017

I'm still struggling with this :( any more ideas how to solve this? I'd love go keep generating the packages from the csproj and not manually by nuspec/cakebuild or similar.

@rohit21agrawal
Copy link
Contributor

rohit21agrawal commented Aug 15, 2017

@Roemer you can add files to your package more dynamically as follows:

An extension point has been provided for executing custom target in the inner build for files that go in the lib (or folder specified via BuildOutputTargetFolder) . A user can write their own custom target and specify it as the value of the property $(TargetsForTfmSpecificBuildOutput). The target should write out any files that need to go into the lib folder into the ItemGroup BuildOutputInPackage and set the following two metadata values :
a) FinalOutputPath : This is the absolute path of the file on disk.
b) TargetPath : This is optional and defaults to the name of the file. Users need to set it when the file needs to go into a subfolder within lib<TFM> like satellite assemblies which go under their respective culture folders.

Reference: NuGet/NuGet.Client#1255

If you have more questions about how to use the above, let me know.

@Roemer
Copy link
Author

Roemer commented Aug 16, 2017

I tried it a bit but didn't bring it to work.

I added

  <PropertyGroup>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetMyPackageFiles</TargetsForTfmSpecificBuildOutput>
  </PropertyGroup>

  <Target Name="GetMyPackageFiles">
    <ItemGroup>
      <BuildOutputInPackage Include="$(OutDir)\Interop.UIAutomationClient.dll">
        <FinalOutputPath>$([System.IO.Path]::GetFullPath('$(OutDir)\Interop.UIAutomationClient.dll'))</FinalOutputPath>
      </BuildOutputInPackage>
    </ItemGroup>
  </Target>

But it doesn't add anything.

@rohit21agrawal
Copy link
Contributor

@Roemer what version of dotnet sdk are you using? and what version of VS?

@Roemer
Copy link
Author

Roemer commented Aug 16, 2017

Visual Studio 2017 Version 15.2 (26430.16)

@rohit21agrawal
Copy link
Contributor

@Roemer 15.2 doesn't have this feature. could you please update to 15.3? It was released yesterday.
also if you have dotnet sdk 2.0 preview bits installed, please upgrade to RTM bits.

let me know if you need links to download the above.

@Roemer
Copy link
Author

Roemer commented Aug 16, 2017

Interesting that my VS doesn't show me an update. I now started the Installer manually (which then updated itself first) which now shows me the update (but not VS itself). Will do that now.
Do I need dotnet sdk 2.0 (I have a pre 2.0 version)

@rohit21agrawal
Copy link
Contributor

yes you should update to dotnet sdk 2.0 as well.
The link to VS download is here: https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes

@Roemer
Copy link
Author

Roemer commented Aug 16, 2017

I updated VS to 2017.3 and now the xml I posted above works!

@Roemer
Copy link
Author

Roemer commented Aug 16, 2017

Is there a way to enforce a project to a minimum VS version?

@Roemer
Copy link
Author

Roemer commented Aug 16, 2017

I now in the end ended up with:

  <ItemGroup Label="Additional nuget files">
    <None Include="..\..\LICENSE.txt" Pack="true" PackagePath="" />
    <None Include="..\..\CHANGELOG.md" Pack="true" PackagePath="" />
  </ItemGroup>

  <PropertyGroup>
    <TargetsForTfmSpecificBuildOutput>$(TargetsForTfmSpecificBuildOutput);GetInteropFile</TargetsForTfmSpecificBuildOutput>
  </PropertyGroup>

  <Target Name="GetInteropFile">
    <ItemGroup>
      <BuildOutputInPackage Include="$(OutDir)\Interop.UIAutomationClient.dll">
        <FinalOutputPath>$([System.IO.Path]::GetFullPath('$(OutDir)\Interop.UIAutomationClient.dll'))</FinalOutputPath>
      </BuildOutputInPackage>
    </ItemGroup>
  </Target>

Which adds LICENSE.txt and CHANGELOG.md to the root of the nuget and the appopriate Interop.UIAutomationClient.dll from the tfm specific build output into the tfm specific lib folder in nuget.

It seems to work. Is this the correct usage?

@rohit21agrawal
Copy link
Contributor

Yea this looks good.
Sorry, i don't know the answer to enforcing a project to a minimum vs version

@rohit21agrawal
Copy link
Contributor

If you are satisfied with the solution, can Iclose this issue?

@Roemer
Copy link
Author

Roemer commented Aug 16, 2017

Since you approved the xml I gave above and it works, you can close it. Thanks for your help!

@rrelyea
Copy link
Contributor

rrelyea commented Aug 16, 2017

@Roemer - i think you may be able to, at the solution level, require a certain version of Visual Studio in order to be able to open it. See info in this page...to help you understand how you might do it: https://social.msdn.microsoft.com/Forums/sqlserver/en-US/2d08da92-f16a-4887-935a-e3159104ff2c/visual-studio-2015-sln-that-can-also-be-opened-by-vs2013-and-vs2010?forum=visualstudiogeneral
I am not sure if this is possible at the project level.
If this is successful (or not), please let us know if/how that works.

@Roemer
Copy link
Author

Roemer commented Aug 18, 2017

@rrelyea - Thanks for the hint. The version numbers are a bit strange. Before I had "15.0.26430.14" (which I am not sure which version it is). Now If I create a new solution, I get "15.0.26730.3" which seems to be VS2017.3. Is there any specific logic behind the versioning?

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