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

Files generated during precompile do not get added to compilation #6596

Closed
pranavkm opened this issue Jul 7, 2016 · 5 comments
Closed

Files generated during precompile do not get added to compilation #6596

pranavkm opened this issue Jul 7, 2016 · 5 comments

Comments

@pranavkm
Copy link
Contributor

pranavkm commented Jul 7, 2016

Steps to reproduce

Consider a project.json with a scripts node like so

"scripts": {
    "precompile": "cmd /c echo namespace Test { public class Foo {} } > Test.cs"
  }

Referencing Test.Foo does not work in the first compile when the file is not on disk. Having an empty Test.cs which gets populated during precompile works. It looks like the build is calculating the set of files to compile earlier than precompile. Perhaps it needs to do it after?

dotnet --info output: 1.0.0-preview3-003150

@ocdi
Copy link

ocdi commented Jul 13, 2016

I am trying to use the precompile script to generate some files and have the same issue, the first compile they aren't included. I'm using 1.0.0-preview2-003121.

@stickybun
Copy link

This is also an issue for embedding files which are created during precompile.

For example:

project.json

"buildOptions": {
    "embed": {
      "include": "*.txt"
    }
  }
"scripts": {
    "precompile": [
      "bash -c \"touch $(date +%H%M%S).txt\""
    ]
  }

or on Windows:

  "scripts": {
    "precompile": [
      "cmd /c echo \"\" >>  %time:~1,1%%time:~3,2%%time:~6,2%.txt"
    ]
  }

Program.cs

public static void Main(string[] args)
{
    var embeddedCount = System.Reflection.Assembly.GetEntryAssembly().GetManifestResourceNames().Count(m=>m.EndsWith(".txt"));
    var actualCount = System.IO.Directory.GetFiles(".","*.txt").Length;
    Console.WriteLine($"Number of txt resources: {embeddedCount}, actual number of files: {actualCount}");
}

Output
Number of txt resources: 0, actual number of files: 1
Number of txt resources: 1, actual number of files: 2
Number of txt resources: 2, actual number of files: 3

Expected Output
Number of txt resources: 1, actual number of files: 1

Version: 1.0.0-preview2-003121

@TanukiSharp
Copy link

TanukiSharp commented Sep 2, 2016

I confirm the issue, with 1.0.0-preview2-003121.

@chwarr
Copy link

chwarr commented Nov 1, 2016

This looks like a duplicate of https://github.com/dotnet/cli/issues/1475 to me. That issue mentions a possible workaround: have dummy files that get overwritten by the precompile scripts. This is working for me.

I doubt that this will get fixed, with the planned move to MSBuild-based builds.

(Though I work for Microsoft, I'm not associated with this project.)

@livarcocc
Copy link
Contributor

This will work with preview3.

@msftgits msftgits transferred this issue from dotnet/cli Jan 31, 2020
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

6 participants