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

Nuget Msbuild does not respect excluding TypeScript generated content based on csproj setting. #2166

Closed
rohit21agrawal opened this issue Aug 26, 2017 · 11 comments

Comments

@rohit21agrawal
Copy link

From @rjamesnw on August 24, 2017 7:28

Details about Problem

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

NuGet version (x.x.x.xxx): N/A (in msbuild)

dotnet.exe --version (if appropriate): 1.1.0

VS version (if appropriate): 15.3.2

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

Worked before? If so, with which NuGet version: First time trying

Detailed repro steps so we can see the same problem

  1. Create a .Net Core C# library.

  2. Edit the csproj and set this: <Project Sdk="Microsoft.NET.Sdk.Web">
    WHY? Because this allows compiling (to catch errors) and embedding cshtml files while also creating a library file, and it works great.

  3. # 2 causes the project to reload. Open project settings and set Output Type to "Class Library".

  4. Enable "Generate NuGet package on build" in the project settings under "Package".

  5. Create default tsconfig.json. I had something like:

{
  "compilerOptions": {
    "noImplicitAny": false,
    "noEmitOnError": true,
    "removeComments": false,
    "sourceMap": true,
    "target": "es5"
  },
  "exclude": [
    "node_modules",
    "wwwroot"
  ],
  "compileOnSave": true
}
  1. Create a .ts file.

  2. Enter "var n = 1;" in the .ts file so it has content. On save it should compile (make sure).

  3. Build, and observe the .json files included in obj\{YOUR LIBRARY}.nuspec.

  4. Add this to csproj:

  <ItemGroup>
    <Content Remove="**\*.*" />
  </ItemGroup>
  1. Build again. Observe that .js and .js.map files included, but all other content removed.

Output Issue Example

  <contentFiles>
     <files include="any/netcoreapp1.1/file.js" buildAction="Content" />
     <files include="any/netcoreapp1.1/file.js.map" buildAction="Content" />
   </contentFiles>
 </metadata>
 <files>
   <file src="e:\users\james\documents\visual studio 2017\Projects\ClassLibrary1\ClassLibrary1\bin\Debug\netcoreapp1.1\ClassLibrary1.dll" target="lib\netcoreapp1.1\ClassLibrary1.dll" />
   <file src="e:\users\james\documents\visual studio 2017\Projects\ClassLibrary1\ClassLibrary1\file.js" target="content\file.js" />
   <file src="e:\users\james\documents\visual studio 2017\Projects\ClassLibrary1\ClassLibrary1\file.js" target="contentFiles\any\netcoreapp1.1\file.js" />
   <file src="e:\users\james\documents\visual studio 2017\Projects\ClassLibrary1\ClassLibrary1\file.js.map" target="content\file.js.map" />
   <file src="e:\users\james\documents\visual studio 2017\Projects\ClassLibrary1\ClassLibrary1\file.js.map" target="contentFiles\any\netcoreapp1.1\file.js.map" />
 </files>

Other suggested things

I think that the TypeScript compiler is updating the files and causing msbuild Nuget integration to pick them up, since the build action is buildAction="Content", when in fact the content should be removed.

Verbose Logs

I don't know how to do this, but the project is easy to create, so you can easily do this yourself when checking it out.

Other Comments

This is the issue I am having with another very large project of mine. This has been working perfectly for months, since the web project and libraries were in the same solution, and it compiled and ran the ASP.Net Core MVC project perfectly. I decided to separate the libraries into a separate solution and have packages created for Nuget, but these content files are getting in my way, and also causing build errors when including the packages in other projects. The only work-around is to open the package in the NuGet Package Explorer and remove them manually, but it is easy to forget and very annoying to have to do this on EVERY build.

Copied from original issue: NuGet/Home#5801

@rohit21agrawal
Copy link
Author

From @jainaashish on August 24, 2017 22:13

@rohit21agrawal can you take a look at it? Thanks!

@rohit21agrawal
Copy link
Author

can you try setting <IncludeContentInPack>false</IncludeContentInPack> in your project?

@rohit21agrawal
Copy link
Author

From @rjamesnw on August 25, 2017 1:25

That worked!!! Thanks. ;) I assume though this is just a work-around, since one day I might need to add content and this will be a problem again. For now, it solves my problem.

@rohit21agrawal
Copy link
Author

is it possible for you to just attach a repro project? it will make it much easier to investigate

@rohit21agrawal
Copy link
Author

From @rjamesnw on August 25, 2017 2:49

ClassLibrary1.zip

After build, open the obj\ClassLibrary1.1.0.0.nuspec file see what I mean - but I'm guessing you know that already lol. ;)

@rohit21agrawal
Copy link
Author

From diag logs:

Target "CompileTypeScriptWithTSConfig: (TargetId:55)" in file "C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.3\build\Microsoft.TypeScript.targets" from project "D:\temp\pack5801\ClassLibrary1\ClassLibrary1\ClassLibrary1.csproj" (target "Compile" depends on it):
Task "VsTsc" (TaskId:26)
Task Parameter:ToolPath=C:\Program Files (x86)\Microsoft SDKs\TypeScript (TaskId:26)
Task Parameter:IsFileSystemCaseSensitive=False (TaskId:26)
Task Parameter:TSConfigFile=D:\temp\pack5801\ClassLibrary1\ClassLibrary1\tsconfig.json (TaskId:26)
Task Parameter:YieldDuringToolExecution=True (TaskId:26)
Task Parameter:ProjectDir=D:\temp\pack5801\ClassLibrary1\ClassLibrary1\ (TaskId:26)
Task Parameter:ToolsVersion=2.3 (TaskId:26)
Task Parameter:TypeScriptCompileBlocked=False (TaskId:26)
Task Parameter:ComputeOutputOnly=False (TaskId:26)
Task Parameter:OutputLogFile=obj\Debug\netcoreapp1.1\Tsc.out (TaskId:26)
C:\Program Files (x86)\Microsoft SDKs\TypeScript\2.3\tsc.exe --project "D:\temp\pack5801\ClassLibrary1\ClassLibrary1\tsconfig.json" --listEmittedFiles (TaskId:26)
Output Item(s):
emittedFiles=
file.js
DestinationRelativePath=file.js
file.js.map
DestinationRelativePath=file.js.map (TaskId:26)
Done executing task "VsTsc". (TaskId:26)
Added Item(s):
GeneratedJavascript=
file.js
DestinationRelativePath=file.js
file.js.map
DestinationRelativePath=file.js.map
Task "AssignTargetPath" (TaskId:27)
Task Parameter:
Files=
file.js
DestinationRelativePath=file.js
file.js.map
DestinationRelativePath=file.js.map (TaskId:27)
Task Parameter:RootFolder=D:\temp\pack5801\ClassLibrary1\ClassLibrary1 (TaskId:27)
Output Item(s):
GeneratedJavascriptWithTargetPath=
file.js
DestinationRelativePath=file.js
OriginalItemSpec=file.js
TargetPath=file.js
file.js.map
DestinationRelativePath=file.js.map
OriginalItemSpec=file.js.map
TargetPath=file.js.map (TaskId:27)
Done executing task "AssignTargetPath". (TaskId:27)
Added Item(s):
FilesForPackagingFromProject=
file.js
DestinationRelativePath=file.js
OriginalItemSpec=file.js
TargetPath=file.js
file.js.map
DestinationRelativePath=file.js.map
OriginalItemSpec=file.js.map
TargetPath=file.js.map
Added Item(s):
ContentWithTargetPath=
file.js
DestinationRelativePath=file.js
OriginalItemSpec=file.js
TargetPath=file.js
file.js.map
DestinationRelativePath=file.js.map
OriginalItemSpec=file.js.map
TargetPath=file.js.map
Added Item(s):
Content=
file.js
DestinationRelativePath=file.js
file.js.map
DestinationRelativePath=file.js.map
Done building target "CompileTypeScriptWithTSConfig" in project "ClassLibrary1.csproj".: (TargetId:55)

@rohit21agrawal
Copy link
Author

CC: @natemcmaster

@natemcmaster
Copy link
Contributor

cc @vijayrkn @mlorbetske

@vijayrkn
Copy link

vijayrkn commented Aug 28, 2017

In this case the TypeScriptCompile task is adding the generated items to the Content itemgroup without checking the initial state of the content glob. To fix this in this task, an issue can be filed here - https://github.com/microsoft/typescript/issues

When the below is added to the csproj, it only removes the contents that are present at that time. In this case the generated contents are added later.

 <ItemGroup>
    <Content Remove="**\*.*" />
  </ItemGroup>

MsBuild does not support dynamically evaluating these items during build, pack, publish etc (https://github.com/aspnet/websdk/issues/164)

To fix this, you should be able to add this to the csproj

  <Target Name="RemoveContentFilesFromPackage" AfterTargets="CompileTypeScriptWithTSConfig">
    <ItemGroup>
      <Content Remove="**\*.*" />
    </ItemGroup>
  </Target>

@rjamesnw
Copy link

As I sort of suspected in my original post. Glad to know there's a workaround! ;)

@aspnet-hello
Copy link

This issue is being closed because it has not been updated in 3 months.

We apologize if this causes any inconvenience. We ask that if you are still encountering this issue, please log a new issue with updated information and we will investigate.

ryanbrandenburg pushed a commit that referenced this issue Nov 27, 2018
- Log from inside of HubConnectionContext if the user callback failed.
- Use ThreadPool.QUWI instead of Task.Factory.StartNew.
- Remove try catch from HubConnectionHandler
@ghost ghost locked as resolved and limited conversation to collaborators Dec 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants