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

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

Open
gulbanana opened this issue Apr 13, 2017 · 11 comments
Labels
Area:ContentFiles PackageReference contentFiles folder Functionality:Pack Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Status:Excluded from icebox cleanup Status:Inactive Icebox issues not updated for a specific long time Triage:Investigate
Milestone

Comments

@gulbanana
Copy link

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
Copy link
Contributor

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

@gulbanana
Copy link
Author

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
Copy link
Author

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>

@mishra14 mishra14 added the Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. label Oct 17, 2017
@mishra14 mishra14 added this to the Backlog milestone Oct 17, 2017
@paulinfrancis
Copy link

paulinfrancis commented Nov 7, 2017

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
Copy link
Contributor

@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
Copy link
Contributor

@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
Copy link
Author

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

@paulinfrancis
Copy link

paulinfrancis commented Nov 8, 2017

@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
Copy link
Contributor

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

@paulinfrancis
Copy link

paulinfrancis commented Nov 8, 2017

@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
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:ContentFiles PackageReference contentFiles folder Functionality:Pack Priority:3 Issues under consideration. With enough upvotes, will be reconsidered to be added to the backlog. Status:Excluded from icebox cleanup Status:Inactive Icebox issues not updated for a specific long time Triage:Investigate
Projects
None yet
Development

No branches or pull requests

8 participants