NuGet / Home

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

ContentFiles, buildAction and copyToOutput wont work for ASP.NET MVC5, but does for ASP.NET Core #6894

Closed 304NotModified closed 6 years ago

304NotModified commented 6 years ago

Details about Problem

We have probably the same issue as https://github.com/NuGet/Home/issues/6404, but it's reproducible.

NuGet product ui: VS UI

NuGet version (x.x.x.xxx): 4.6.0

VS version (if appropriate): VS2017 (15.6.5),

OS version (i.e. win10 v1607 (14393.321)): win 10 enterprise

Worked before? If so, with which NuGet version: not that i'm aware of

Detailed repro steps so we can see the same problem

  1. Create a new ASP.NET MVC 5 application (I choose .net 4.5.2)
  2. Install the package NLog.Config (https://www.nuget.org/packages/NLog.config) - version 4.5.3
  3. Check the properties of the added NLog.config:

image

expected:

current:

...

Other suggested things

it works for a new ASP.NET Core website

image

the nuspec in the package:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
  <metadata>
    <id>NLog.Config</id>
    <version>4.5.3</version>
    <title>NLog Configuration</title>
    <authors>Kim Christensen, Julian Verdurmen</authors>
    <owners>Kim Christenen, Julian Verdurmen</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <licenseUrl>http://raw.github.com/NLog/NLog/master/LICENSE.txt</licenseUrl>
    <projectUrl>http://nlog-project.org/</projectUrl>
    <iconUrl>http://nlog-project.org/NConfig.png</iconUrl>
    <description>Xml file to get started with configuring NLog. This package is not mandatory to get started with NLog: the configuration file can created manually and the configuration can be created programmatically.</description>
    <summary>Configuration file for NLog.</summary>
    <releaseNotes>NLog 4.5.3</releaseNotes>
    <language>en-US</language>
    <tags>nlog, xml, config</tags>
    <dependencies>
      <dependency id="NLog" version="4.5.3" />
      <dependency id="NLog.Schema" version="4.5.3" />
    </dependencies>
    <contentFiles>
      <files include="**/*.*" buildAction="None" copyToOutput="true" flatten="true" />
    </contentFiles>
  </metadata>
</package>

The content of the nupkg:

image

Verbose Logs

Not sure which logs I could add .

Sample Project

not sure if useful, as it's an install thing.

304NotModified commented 6 years ago

I think it found the issue, I still need a install.ps1?

PatoBeltran commented 6 years ago

@jainaashish @nkolev92 can any of you take a look at this?

304NotModified commented 6 years ago

I pretty sure it's my mistake. I read the docs wrong.

For maximum compatibility with consuming projects, a package ideally specifies the content files in both elements.

I did that, but before there was an install.ps1, and that one was missing now. For some reason I was thinking that the ps1 wasn't need with the <contentFiles> config

nkolev92 commented 6 years ago

@304NotModified You don't need install.ps1 with contentFiles. contentFiles => PackageReference, project.json content => packages.config

The asp.net project you have is probably a packages.config one, so for that content is used.

304NotModified commented 6 years ago

yes indeed, but I still need the install.ps1 for setting the buildAction etc when using packages.config. Correct?

nkolev92 commented 6 years ago

@304NotModified Correct. Just wanted to make sure we're on the same page :)

304NotModified commented 6 years ago

OK thanks for the confirmation :) 👍

mcpine9 commented 6 years ago

I am unable to get this working. I am having the same issue as #6404. As the title states, "ContentFiles, buildAction and copyToOutput wont work." This goes for a class library as well. Here is my .nuspec file:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
  <metadata>
    <id>$id$</id>
    <version>$version$</version>
    <title>$title$</title>
    <authors>FIS</authors>
    <owners>$author$</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>EMV Library</description>
    <releaseNotes>First Version using TFS Build Definition.</releaseNotes>
    <copyright>Copyright 2018</copyright>
    <contentFiles>
      <files include="EMVLibWrapper\*.dll" buildAction="None" copyToOutput="true" />
    </contentFiles>
  </metadata>
    <files>
      <file src="bin\$Configuration$\Psg.Common.*.dll" target="lib\net462" />
      <file src="bin\$Configuration$\Psg.Common.*.pdb" target="lib\net462" />
      <file src="App.config.install.xdt" target="content\" />
      <file src="App.config.uninstall.xdt" target="content\" />
    </files>
</package>

When I create the package the items in contentFiles do not apply "buildAction = None" nor "copyToOutput = true". Build action is set to "Content" and Copy to Output Directory is set to "Do not copy".

Please help. Thank you, Mark

304NotModified commented 6 years ago

we having also problems: see https://github.com/NLog/NLog/issues/2823

jainaashish commented 6 years ago

@mcpine9 ContentFiles only applicable when installed into a project using PackageReference... so if you're trying to install it with packages.config then it won't work. You'd need to explicitly set those properties either through MSBuild targets (highly recommended) or powershell scripts like install.ps1...