Repository: conan-io/conan

Issue:
Error using lockfiles with conanfile.txt
Using: Windows and conan version 1.17.1

I get `ERROR: Unspecified reference in graph-lock, please specify` when trying to use lockfiles in a package that has `conanfile.txt` instead of `conanfile.py`

To reproduce:
```
git clone https://github.com/conan-io/examples.git
cd examples/libraries/poco/md5
mkdir build && cd build
conan install ..
conan install .. --lockfile
```
Output:
```
Using lockfile: 'C:\temp\examples\libraries\poco\md5\build\conan.lock'
Configuration:
[settings]
arch=x86_64
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.runtime=MD
compiler.version=15
os=Windows
os_build=Windows
[options]
[build_requires]
[env]

ERROR: Unspecified reference in graph-lock, please specify
```

- [X] I've read the [CONTRIBUTING guide](https://github.com/conan-io/conan/blob/develop/.github/CONTRIBUTING.md).
- [X] I've specified the Conan version, operating system version and any tool that can be relevant.
- [X] I've explained the steps to reproduce the error or the motivation/use case of the question/suggestion.




Discussion:
I have the same issue, is there a workaround other than switching to `conanfile.py`? I'm trying to lock dependencies for a project (which doesn't have Conan package by itself).

Resolving patch:
diff --git a/conans/model/graph_lock.py b/conans/model/graph_lock.py
--- a/conans/model/graph_lock.py
+++ b/conans/model/graph_lock.py
@@ -292,10 +292,10 @@ def get_node(self, ref):
         """
         # None reference
         if ref is None:
-            try:
-                return self._nodes[None].pref
-            except KeyError:
-                raise ConanException("Unspecified reference in graph-lock, please specify")
+            # Is a conanfile.txt consumer
+            for id_, node in self._nodes.items():
+                if not node.pref and node.path:
+                    return id_
 
         # First search by ref (without RREV)
         ids = []


Test patch:
diff --git a/conans/test/functional/graph_lock/graph_lock_test.py b/conans/test/functional/graph_lock/graph_lock_test.py
--- a/conans/test/functional/graph_lock/graph_lock_test.py
+++ b/conans/test/functional/graph_lock/graph_lock_test.py
@@ -29,6 +29,34 @@ def update_different_profile_test(self):
         self.assertIn("os=Linux", client.out)
 
 
+class GraphLockConanfileTXTTest(unittest.TestCase):
+    def conanfile_txt_test(self):
+        client = TestClient()
+        client.save({"conanfile.txt": ""})
+        client.run("install .")
+        client.run("install . --lockfile")
+        self.assertIn("Using lockfile", client.out)
+
+    def conanfile_txt_deps_test(self):
+        client = TestClient()
+        client.save({"conanfile.py": GenConanfile()})
+        client.run("create . pkg/0.1@user/testing")
+
+        client2 = TestClient(cache_folder=client.cache_folder)
+        client2.save({"conanfile.txt": "[requires]\npkg/[>0.0]@user/testing"})
+        client2.run("install .")
+        self.assertIn("pkg/0.1@user/testing from local cache - Cache", client2.out)
+
+        client.run("create . pkg/0.2@user/testing")
+
+        client2.run("install . --lockfile")
+        self.assertIn("pkg/0.1@user/testing from local cache - Cache", client2.out)
+        self.assertNotIn("pkg/0.2", client2.out)
+        client2.run("install .")
+        self.assertIn("pkg/0.2@user/testing from local cache - Cache", client2.out)
+        self.assertNotIn("pkg/0.1", client2.out)
+
+
 class GraphLockCustomFilesTest(unittest.TestCase):
     consumer = GenConanfile().with_name("PkgB").with_version("0.1")\
                              .with_require_plain("PkgA/[>=0.1]@user/channel")