NuGet / Home

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

Packed contentFiles are included as source code even when they're some other form of content #5024

Open gulbanana opened 7 years ago

gulbanana commented 7 years ago

I've got an sdk project for building a nuget package which includes this section:

  <ItemGroup>
    <Content Include="wwwroot\*.d.ts" PackagePath="contentfiles\any\any\typings\" />
  </ItemGroup>

The goal is to provide typescript definition files to consumers of the package. I don't want them to be compiled as C# files, and the item isn't of type Compile.

The generated package contains the content files at the specified path. However, when my package is referenced by some project, it tries to compile the files with csc.

rohit21agrawal commented 7 years ago

@gulbanana can you paste your generated nuspec ? (you can find it in the obj folder)

gulbanana commented 7 years ago

Here is the generated nuspec:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
  <metadata>
    <id>The.Web</id>
    <version>162.0.0</version>
    <title>foo</title>
    <authors>bar</authors>
    <owners>bar</owners>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>baz</description>
    <dependencies>
      <group targetFramework=".NETFramework4.6.1">
        <dependency id="Microsoft.Extensions.FileProviders.Embedded" version="1.1.0" exclude="Build,Analyzers" />
      </group>
    </dependencies>
  </metadata>
  <files>
    <file src="C:\code\framework\The.Web\bin\Release\net461\The.Web.dll" target="lib\net461\The.Web.dll" />
    <file src="C:\code\framework\The.Web\wwwroot\app.d.ts" target="contentfiles\any\any\typings\app.d.ts" />
  </files>
</package>
gulbanana commented 7 years ago

The original project file:

<Project ToolsVersion="15.0" Sdk="Microsoft.NET.Sdk">
  <!-- Build/Package settings -->
  <PropertyGroup>
    <TargetFramework>net461</TargetFramework>    
    <DebugType>full</DebugType>
    <VersionPrefix>162.0.0</VersionPrefix>
    <Title>foo</Title>
    <Description>baz</Description>
    <Authors>bar</Authors>
  </PropertyGroup>

  <!-- Dependencies -->
  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.FileProviders.Embedded" Version="1.1.0" />
  </ItemGroup>

  <!-- Source files -->
  <ItemGroup>
    <Content Include="wwwroot\*.d.ts" PackagePath="contentfiles\any\any\typings\" />
  </ItemGroup>

  <!-- Compile TS before bundling -->
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props" Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')" />
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets" Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.targets')" />
  <Target Name="PrecompileTypescript" BeforeTargets="BundleMinify" DependsOnTargets="$(CompileTypeScriptDependsOn)" Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\TypeScript\Microsoft.TypeScript.Default.props')">
    <VsTsc TSConfigFile="tsconfig.json" ToolPath="$(TscToolPath)" ToolExe="$(TscToolExe)" YieldDuringToolExecution="$(TscYieldDuringToolExecution)" ProjectDir="$(TypeScriptProjectDir)" ToolsVersion="$(TypeScriptToolsVersion)" OutputLogFile="$(CompilerOutputLog)" TypeScriptCompileBlocked="$(TypeScriptCompileBlocked)" PreferredUILang="$(PreferredUILang)" ComputeOutputOnly="false" />
  </Target>
</Project>
paulinfrancis commented 7 years ago

I'm also experiencing this issue. The files appear in Visual Studio as expected, but if I look in project.assets.json, all my PowerShell files are listed with "buildAction": "Compile", and not "None", as specified in the nuspec.

When I build the project, the C# compiler tries to build the PS scripts, and that ends in tears.

Installing the package and building with the dotnet CLI and VS both yield the same result.

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">>
    <metadata minClientVersion="3.3.0">
        <id>FooPackageName</id>
        <version>1.0.0</version>
        <authors>Francis Paulin</authors>
        <owners>Francis Paulin</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>Build and deploy helper scripts.</description>
        <copyright>Francis Paulin</copyright>
        <dependencies>
            <group targetFramework=".NETStandard1.0"></group>
        </dependencies>
        <contentFiles>
            <files include="**/scripts/*.*" buildAction="None" copyToOutput="true" flatten="false" />
        </contentFiles>
    </metadata>
    <files>
        <file src="scripts\**" target="contentFiles\any\any\scripts" />
    </files>
</package>

> dotnet --version 2.0.2

Visual Studio 2017 15.4.1

jainaashish commented 7 years ago

@paulinfrancis can you make sure you've the right package folder structure in project before packing this nuspec, which is /contentFiles/{codeLanguage}/{TxM}/? Also seems like you don't need files tag which is specified outside of metadata tag. You just need ContentFiles. Please refer https://docs.microsoft.com/en-us/nuget/schema/nuspec#including-content-files to get more details about package folder structure.

rohit21agrawal commented 7 years ago

@jainaashish either should work - you can either have the convention based folder structure or use the files tag to include files and then also add them as contentFiles

gulbanana commented 7 years ago

also, that nuspec is the one which was generated (incorrectly) by nuget packtasks. it wasn’t hand written.

paulinfrancis commented 7 years ago

@jainaashish I've done another test, and the same behaviour as previously mentioned is exhibited; the C# compiler tries to compile the PowerShell scripts.

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2013/01/nuspec.xsd">
    <metadata minClientVersion="3.3.0">
        <id>FooPackageName</id>
        <version>1.0.0</version>
        <authors>Francis Paulin</authors>
        <owners>Francis Paulin</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>Build and deploy helper scripts.</description>
        <copyright>Francis Paulin</copyright>
        <dependencies>
            <group targetFramework=".NETStandard1.0"></group>
        </dependencies>
        <contentFiles>
            <files include="contentFiles/any/any/scripts/*.*" buildAction="None" copyToOutput="true" />
        </contentFiles>
    </metadata>
</package>

@rohit21agrawal I was also under the impression that files and contentFiles aren't mutually exclusive, and that they serve separate purposes.

rohit21agrawal commented 7 years ago

What does the generated nuspec file within the nupkg look like?

paulinfrancis commented 7 years ago

@rohit21agrawal

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
    <metadata>
        <id>FooPackageName</id>
        <version>1.0.0</version>
        <authors>Francis Paulin</authors>
        <owners>Francis Paulin</owners>
        <requireLicenseAcceptance>false</requireLicenseAcceptance>
        <description>Build and deploy helper scripts.</description>
        <copyright>Francis Paulin</copyright>
        <dependencies>
            <group targetFramework=".NETStandard1.0" />
        </dependencies>
    </metadata>
</package>

EDIT:

So I can see that the contentFiles node is missing. I generated the nuget-package with the nuget package explorer.

I have just tried generating the package using nuget.exe pack foopackage.nuspec.

The nuspec within the package now contains the contentFiles node, but the behaviour in VS is still the same; the C# compiler tries to compile the ps1 scripts.

rohit21agrawal commented 6 years ago

@paulinfrancis please paste the foopackage.nuspec file and the nuspec file that was generated within the package.