C
C#2y ago
exokem

Unresolved NuGet Dependency References

I have XUnit added as a dependency to my test project via NuGet. Despite this, my test project code seems to oscillate inexplicably between recognizing all of the dependency references and not. This doesn't really make any sense to me as I can successfully build and run the test project, but when I reload it all of the references become unrecognized. I have been using visual studio to set up projects/dependencies and working in VSCode, and even if I can build everything in VS just trying to scan for the test projects in VSC loses the dependency references.
20 Replies
exokem
exokemOP2y ago
these are all of the NuGet packages my project has installed
exokem
exokemOP2y ago
it's just XUnit that isn't working all the time I have other projects in the solution that do not have the same issue
sibber
sibber2y ago
you are importing the namespace right? just to make sure
exokem
exokemOP2y ago
it doesn't even recognize the namespace literally every other build succeeds
sibber
sibber2y ago
have you tried deleting the .vs folder and obj and whatever other stuff it generates then run dotnet restore then open vs
exokem
exokemOP2y ago
should I run restore on the solution directory? I have multiple csproj projects in the solution
exokem
exokemOP2y ago
this is the file structure with all of the csproj files
exokem
exokemOP2y ago
the test project only includes Xylem/test the main project (Xylem) includes Xylem/data and Xylem/src
sibber
sibber2y ago
sure
exokem
exokemOP2y ago
I think Xylem and Xytest are using the same obj path for building so building one clears the dependency files for the other I probably need to separate the structure
sibber
sibber2y ago
why do you even set the path
exokem
exokemOP2y ago
what do you mean I haven't made any manual changes to anything in any case I have rearranged the projects so no two csproj share the same folder and everything seems fine
sibber
sibber2y ago
oh they were sharing a folder
exokem
exokemOP2y ago
yea
sibber
sibber2y ago
yeah don't do that $structure
MODiX
MODiX2y ago
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
namespace Namespace;

[Attribute]
public class Class
{
public string PublicField;
private bool _privateField;
protected double protectedField;

public int PublicProperty { get; set; }

public Class() {} // Constructor

public void Method(int parameter)
{
var localVariable = parameter;
}
}
For C# versions older than 10, see $StructureOld
sibber
sibber2y ago
oops not that one anyway generally i have a src folder for the actual app and a tests folder
exokem
exokemOP2y ago
I had the main/test project separate so I wanted to move the tests into the main project without adding the XUnit dependency to the main project so my structure is like this now:
MainProject
src
test
TestProject.csproj
MainProject.csproj
MainProject
src
test
TestProject.csproj
MainProject.csproj
and the MainProject excludes the test directory
sibber
sibber2y ago
thats worse imo and probably most peoples opinion just have the tests directory under the root, completely seperate from source
exokem
exokemOP2y ago
I was thinking I needed the data directory which is at the same level as src but I don't actually so that does make sense
Want results from more Discord servers?
Add your server