Code Monkey home page Code Monkey logo

mvssln's People

Contributors

3f avatar wouterroos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mvssln's Issues

More simplified work with solution folders

new SolutionFolder
(
	new ProjectItem()
	{
		pType = Guids.SLN_FOLDER,
		name = "MyFolder1",
		path = "MyFolder1", // recommended to be same
		pGuid = Guid.NewGuid().ToString()
	},
	new List<RawText>()
	{
		".gnt\\gnt.core",
		".gnt\\packages.config",
		// ...
	}
),
...

too verbose ...

Related issue: #6

Getting the Assembly that will be produced by a .NET project...

PRetty sure I am missing, but I have spend a few hours, and just don't see it as a property of the Project type classes.

background: I am processing a huge system. Assembly references rather than project references are used. I need to generate the association between the proj file that creates and assembly and the proj file(s) that reference it...

Thanks in advance.

Loading .vxproj from sln....

Do not see a way to get the "tools version passes... In xProjectEnv.cs it appears to be a hard coded null....

protected virtual Project Load(RawText raw, IDictionary<string, string> properties) { using(var reader = XmlReader.Create(new StreamReader(raw.data.GetStream(raw.encoding), raw.encoding))) { return new Project(reader, properties, **null**, PrjCollection); } }

C++ projects and their initialization via Microsoft.Build.Evaluation

yes, again...
https://social.msdn.microsoft.com/Forums/en-US/2badfe39-1321-4ec4-9cc8-74bf4efd39b3/

// InvalidProjectFileException:"D:\Microsoft.Cpp.Default.props" - yes, because $(VCTargetsPath) is not defined.
new Project("Sample.vcxproj", new Dictionary<string, string>(), null);

// OK, because I also have 14.0
new Project("Sample.vcxproj", new Dictionary<string, string>(), "14.0");

// InvalidProjectFileException: The tools version "15.0" is unrecognized. 
// Available tools versions are: "12.0", "14.0", "2.0", "3.5", "4.0". - yes, I know why is so -_-
new Project("Sample.vcxproj", new Dictionary<string, string>(), "15.0");
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
  <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
</Project>

-_-

Looks like the most easy way should be init by null and to define related properties to .ctor. I think should work o_o

Allow '.' character in solution/project configuration name by improving code that determines the project configuration properties

public override bool Positioned(ISvc svc, RawText line)

Current implementation looks ahead for '.' characters to isolate the various properties for a project configuration. However, the '.' is, as far as I know, a valid character for a solution/project configuration name. The current code breaks functionality when including a '.' in a solution/project name, resulting in the configuration item no longer being properly retrieved when querying the solution.

Unable to load Xamarin Project...

I am trying to load a solution which has xamarin project. I get the following exception.

Microsoft.Build.Exceptions.InvalidProjectFileException : The attribute "Version" in element <PackageReference> is unrecognized.  MyProject.Android.csproj
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Internal.ProjectXmlUtilities.ThrowProjectInvalidAttribute(XmlAttributeWithLocation attribute)
   at Microsoft.Build.Internal.ProjectXmlUtilities.VerifyThrowProjectAttributes(XmlElementWithLocation element, String[] validAttributes)
   at Microsoft.Build.Construction.ProjectParser.ParseProjectItemElement(XmlElementWithLocation element, ProjectItemGroupElement parent)
   at Microsoft.Build.Construction.ProjectParser.ParseProjectItemGroupElement(XmlElementWithLocation element, ProjectElementContainer parent)
   at Microsoft.Build.Construction.ProjectParser.ParseProjectRootElementChildren(XmlElementWithLocation element)
   at Microsoft.Build.Construction.ProjectParser.Parse()
   at Microsoft.Build.Construction.ProjectParser.Parse(XmlDocumentWithLocation document, ProjectRootElement projectRootElement)
   at Microsoft.Build.Construction.ProjectRootElement..ctor(String path, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext)
   at Microsoft.Build.Construction.ProjectRootElement.CreateProjectFromPath(String projectFile, IDictionary`2 globalProperties, String toolsVersion, ILoggingService loggingService, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext)
   at Microsoft.Build.Construction.ProjectRootElement.<>c__DisplayClass169_0.<OpenProjectOrSolution>b__0(String path, ProjectRootElementCache cache)
   at Microsoft.Build.Evaluation.ProjectRootElementCache.Get(String projectFile, OpenProjectRootElement openProjectRootElement, Boolean isExplicitlyLoaded)
   at Microsoft.Build.Construction.ProjectRootElement.OpenProjectOrSolution(String fullPath, IDictionary`2 globalProperties, String toolsVersion, ILoggingService loggingService, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext, Boolean isExplicitlyLoaded)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, ProjectCollection projectCollection)
   at net.r_eg.MvsSln.Core.IsolatedEnv.Load(String path, IDictionary`2 properties) in D:\My Documents\Projects\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 335
   at net.r_eg.MvsSln.Core.IsolatedEnv.Load(ProjectItem pItem, IDictionary`2 properties) in D:\My Documents\Projects\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 323
   at net.r_eg.MvsSln.Core.IsolatedEnv.GetOrLoadProject(ProjectItem pItem, IDictionary`2 properties) in D:\My Documents\Projects\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 209
   at net.r_eg.MvsSln.Core.IsolatedEnv.GetOrLoadProject(ProjectItem pItem, IConfPlatform cfg) in D:\My Documents\Projects\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 170
   at net.r_eg.MvsSln.Core.IsolatedEnv.Load(IEnumerable`1 pItems) in D:\My Documents\Projects\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 312
   at net.r_eg.MvsSln.Core.IsolatedEnv.LoadProjects(IEnumerable`1 pItems) in D:\My Documents\Projects\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 266
   at net.r_eg.MvsSln.Core.SlnParser.Parse(StreamReader reader, SlnItems type) in D:\My Documents\Projects\MvsSln\MvsSln\Core\SlnParser.cs:line 151
   at net.r_eg.MvsSln.Core.SlnParser.Parse(String sln, SlnItems type) in D:\My Documents\Projects\MvsSln\MvsSln\Core\SlnParser.cs:line 103
   at net.r_eg.MvsSln.Sln..ctor(String file, SlnItems type) in D:\My Documents\Projects\MvsSln\MvsSln\Sln.cs:line 54

The project file has the following information.

  <ItemGroup>
    <PackageReference Include="Xamarin.Forms" Version="2.5.0.122203" />
    <PackageReference Include="Xamarin.Android.Support.Design" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v7.AppCompat" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v4" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v7.CardView" Version="25.4.0.2" />
    <PackageReference Include="Xamarin.Android.Support.v7.MediaRouter" Version="25.4.0.2" />
    <PackageReference Include="Microsoft.Azure.Mobile.Client" Version="4.0.1" />
    <PackageReference Include="Microsoft.Azure.Mobile.Client.SQLiteStore" Version="4.0.1" />
  </ItemGroup>

Removal of project/solution configurations...

Over time, project/solutions get lots of build configurations added. I have successfully iterated and found a list and now want to purge...

Going manually into Visual Studio and deleting is not an option (I am looking at nearly 10K kills!!!!)... nut I am also not seeing a way to modify the collections and re-write the respective project (including .vcxproj, and vcsproj) files...

Am I missing something? Are heir any recommendations? Do I have to start writing raw tooling?

Thanks in Advance

creating projects/solutions from scratch

Wanted to try and create a basic project/solution but ran into a good bit of difficulty.

Below is the code I tried, I had to fallback to MS to generate the project itself and then still had problems.

While there is no example of creating a project like this there is an example of creating an issue from scratch here. Sadly the solution had several problems even (like missing global section).

Here is what 'worked' but required various manual fixes (including commented out versions of what didn't work). Not sure if there is a better way:

	Microsoft.Build.Locator.MSBuildLocator.RegisterDefaults();
}
public void DoExport(String baseDir, String projName, Message msg) {

	if (Directory.Exists(baseDir))
		Directory.Delete(baseDir, true);
	Directory.CreateDirectory(baseDir);
	var solutionFile = Path.Combine(baseDir, projName + ".sln");
	var header = new SlnHeader();
	header.SetFormatVersion("12.0");
	header.SetMinimumVersion("10.0.40219.1");
	var platformData = new List<IConfPlatform>() {
		new ConfigSln("Debug", "x64"),
	};


	var projects = new[] { new ProjectItem(projName, ProjectType.CsSdk, $"{projName}.csproj") };
	var raw_proj = new WProject(projects, new LProjectDependencies());
	var platformProjData = new List<IConfPlatformPrj>() {
		new ConfigPrj(projects[0].name,projects[0].pGuid,true,platformData[0] as ConfigSln),
	};
	var whandlers = new Dictionary<Type, HandlerValue>() {
		[typeof(LVisualStudioVersion)] = new HandlerValue(new WVisualStudioVersion(header)),
		[typeof(LProject)] = new HandlerValue(raw_proj),
		//[typeof(global)] = new HandlerValue(raw_proj),
		[typeof(LProjectConfigurationPlatforms)] = new HandlerValue(new WProjectConfigurationPlatforms(platformProjData)),
		[typeof(LSolutionConfigurationPlatforms)] = new HandlerValue(new WSolutionConfigurationPlatforms(platformData)),

	};
	//  xp.AddReference(typeof(JsonConverter).Assembly, true);
	using (var w = new SlnWriter(solutionFile, whandlers)) {
		w.Write([
			new Section(new LVisualStudioVersion(), null),
			new Section(new LProject(), null),
			new Section(new LProjectConfigurationPlatforms(), null),
			new Section(new LSolutionConfigurationPlatforms(), null),
		]);

	}
	var manFixes = File.ReadAllText(solutionFile);
	manFixes = manFixes.Replace("\r", "");
	manFixes = manFixes.Replace("EndProject\n", "EndProject\nGlobal\n");
	manFixes += "\nEndGlobal\n";
	manFixes = manFixes.Replace("TestProj|", "Debug|x64");
	File.WriteAllText(solutionFile, manFixes);
	using (var sln = new Sln(solutionFile, SlnItems.Env)) {
		//var env = new XProjectEnvStub(sln.Result, cfgsln);
		var projItemConfig = new ProjectItemCfg(projects[0], sln.Result.DefaultConfig, sln.Result.ProjectConfigurationPlatforms.First().Value.First());
		//var msProj = new Microsoft.Build.Evaluation.Project(sln.Result.ProjectItems.First().fullPath);
		//var msProj = new Microsoft.Build.Evaluation.Project(Microsoft.Build.Evaluation.NewProjectFileOptions.None);
		//var msProj = Microsoft.Build.Construction.ProjectRootElement.Create(sln.Result.ProjectItems.First().fullPath,Microsoft.Build.Evaluation.NewProjectFileOptions.IncludeAllOptions);
		var msProj = Microsoft.Build.Construction.ProjectRootElement.Create(sln.Result.ProjectItems.First().fullPath, Microsoft.Build.Evaluation.NewProjectFileOptions.None);
		msProj.Sdk = "Microsoft.NET.Sdk";
		var rGroup = msProj.AddPropertyGroup();
		rGroup.AddProperty("OutputType", "EXE");
		rGroup.AddProperty("TargetFramework", "net8.0");
		rGroup.AddProperty("Platforms", "x64");
		msProj.Save();
		//msProj.ItemGroups.First().AddItem();
		//var rGroup = msProj.AddPropertyGroup();
		//msProj.AddProperty("RootNamespace", projects[0].name);
		//var proj = sln.Result.Env.LoadProjects([projItemConfig]).First();
		var proj = sln.Result.Env.LoadProjects().Single();
		//var proj = sln.Result.Env.Projects.Single();
		//sln.Result.Env.AddOrGet(msProj);
		//msProj.AddItem("Compile", @"Program.cs");
		//var proj = sln.Result.Env.LoadProjects([projItemConfig]).First();

		//}
		//using (var sln = new Sln(solutionFile, SlnItems.All)) {
		//var proj = sln.Result.Env.Projects.First();


		foreach (var dll in msg.ReferencedAssemblies) {
			var fInfo = new FileInfo(dll);
			proj.AddReference(fInfo.Name.Substring(0, fInfo.Name.Length - 4), dll, false);
		}
		var refs = proj.GetReferences();
		
		
		//refs.ForEach( imp =>  {
		//	var newProps = new RoProperties<string, net.r_eg.MvsSln.Projects.Item.Metadata>(imp.meta.Where(a=>a.Key.Equals("Private",StringComparison.CurrentCultureIgnoreCase) == false).ToDictionary());
		//	imp.meta = newProps;
		//		}
		//);//nope doesn't work

		//refs.ForEach(a=>a.meta.Remove("Private",out _));
		//proj.SetProperty("Sdk","Microsoft.NET.Sdk");
		proj.Save();

		manFixes = File.ReadAllText(msProj.FullPath);
	manFixes = manFixes.Replace("<Private>False</Private>","");
	File.WriteAllText(msProj.FullPath, manFixes);

Drop MSBuild

This question has been raised a very long time. As I already mentioned:

Modern #MSBuild assemblies are much more closely integrated with #VisualStudio and much more difficult to maintain independently

ie. without VS/dotnet sdk dependencies.

We need to consider more independent implementation as possible. At least for an alternative way.

Why

How

Either basing on original https://github.com/microsoft/msbuild (MIT) or from scratch.

What

  • Compatible Evaluator engine.
  • Basic manipulation with XML nodes.

Where

At least for public:

slnEnv Variable in README.MD

See:

fig01

What's this variable? Where is it declared? Kindly please add the declaration of this variable to the example code, so that I might know why it's there/how to utilize this package.

Respectfully,

Brian H

DEaling with Properties in .??proj when the original definition is in a nested .props file...

My goes is (still) to identify settings, be able to report on them, then be able to standardize them.... Hereis an example along with the error i am getting...

image

Also, many properties that are defined in a nested .props fail I have been unsuccessful in finding...

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ImportGroup Label="PropertySheets" />
  <PropertyGroup Label="UserMacros" />
  <PropertyGroup />
  <ItemDefinitionGroup>
    <ClCompile>
      <WarningLevel>Level3</WarningLevel>
    </ClCompile>
  </ItemDefinitionGroup>
  <ItemDefinitionGroup>
    <Midl>
      <HeaderFileName>%(Filename).h</HeaderFileName>
      <InterfaceIdentifierFileName>%(Filename)_i.c</InterfaceIdentifierFileName>
      <TypeLibraryName>%(Filename).tlb</TypeLibraryName>
    </Midl>
  </ItemDefinitionGroup>
  <ItemGroup />
</Project>

Then in the vcxProj...

  <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Typelib|Win32'" Label="PropertySheets">
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
    <Import Project="..\..\..\..\Bldtools\PropertySheets\CustomLevel1.Typelib.Win32.props" />
    <Import Project="..\..\..\..\Bldtools\PropertySheets\CustomLEeel2.Typelib.Win32.props" />
  </ImportGroup>

Handlers for `NestedProjects` when solution folders

This feature is related to the Issue #6

raw overview:

Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "MyFolder1", "MyFolder1", "{6089ABB0-C1B3-4104-A422-DF223328B81C}"
EndProject

^

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bridge", "Bridge\Bridge.csproj", "{73919171-44B6-4536-B892-F1FCA653887C}"
EndProject

^

GlobalSection(NestedProjects) = preSolution
	{73919171-44B6-4536-B892-F1FCA653887C} = {6089ABB0-C1B3-4104-A422-DF223328B81C}
EndGlobalSection

I've plan to consider this issue in the current month. But anyone else may also help to add this r/w handlers.

Cannot load UWP projects

Thanks a lot for your great library! When going over a rather big solution I found a problem related to UWP project. I worked around the issue by simply ignoring the UWP projects for now.

Project:

https://github.com/mrexodia/ClangPowerToolsUwpTest

Code:

using net.r_eg.MvsSln;
using System;

namespace VsProjectStuff
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var sln = new Sln(@"c:\CodeBlocks\ClangPowerToolsUwpTest\UwpTest.sln", SlnItems.All))
                foreach (var project in sln.Result.ProjectItems)
                    Console.WriteLine($"guid: {project.pGuid}, path: {project.path}");
        }
    }
}

Exception:

Invalid static method invocation syntax: "[Microsoft.Build.Utilities.ToolLocationHelper]::GetPlatformSDKDisplayName($(SDKIdentifier), $(SDKVersion))". Method 'Microsoft.Build.Utilities.ToolLocationHelper.GetPlatformSDKDisplayName' not found. Static method invocation should be of the form: $([FullTypeName]::Method()), e.g. $([System.IO.Path]::Combine(`a`, `b`)). 

   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(String errorSubCategoryResourceName, IElementLocation elementLocation, String resourceName, Object[] args)
   at Microsoft.Build.Shared.ProjectErrorUtilities.ThrowInvalidProject(IElementLocation elementLocation, String resourceName, Object arg0, Object arg1)
   at Microsoft.Build.Evaluation.Expander`2.Function`1.Execute(Object objectInstance, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation)
   at Microsoft.Build.Evaluation.Expander`2.PropertyExpander`1.ExpandPropertyBody(String propertyBody, Object propertyValue, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties)
   at Microsoft.Build.Evaluation.Expander`2.PropertyExpander`1.ExpandPropertiesLeaveTypedAndEscaped(String expression, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties)
   at Microsoft.Build.Evaluation.Expander`2.PropertyExpander`1.ExpandPropertiesLeaveEscaped(String expression, IPropertyProvider`1 properties, ExpanderOptions options, IElementLocation elementLocation, UsedUninitializedProperties usedUninitializedProperties)
   at Microsoft.Build.Evaluation.Expander`2.ExpandIntoStringLeaveEscaped(String expression, ExpanderOptions options, IElementLocation elementLocation)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluatePropertyElement(ProjectPropertyElement propertyElement)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluatePropertyGroupElement(ProjectPropertyGroupElement propertyGroupElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.EvaluateImportElement(String directoryOfImportingFile, ProjectImportElement importElement)
   at Microsoft.Build.Evaluation.Evaluator`4.PerformDepthFirstPass(ProjectRootElement currentProjectOrImport)
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate()
   at Microsoft.Build.Evaluation.Evaluator`4.Evaluate(IEvaluatorData`4 data, ProjectRootElement root, ProjectLoadSettings loadSettings, Int32 maxNodeCount, PropertyDictionary`1 environmentProperties, ILoggingService loggingService, IItemFactory`2 itemFactory, IToolsetProvider toolsetProvider, ProjectRootElementCache projectRootElementCache, BuildEventContext buildEventContext, ProjectInstance projectInstanceIfAnyForDebuggerOnly)
   at Microsoft.Build.Evaluation.Project.ReevaluateIfNecessary(ILoggingService loggingServiceForEvaluation)
   at Microsoft.Build.Evaluation.Project.Initialize(IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectLoadSettings loadSettings)
   at Microsoft.Build.Evaluation.Project..ctor(String projectFile, IDictionary`2 globalProperties, String toolsVersion, String subToolsetVersion, ProjectCollection projectCollection, ProjectLoadSettings loadSettings)
   at net.r_eg.MvsSln.Core.IsolatedEnv.Load(String path, IDictionary`2 properties) in D:\prg\projects\MvsSln\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 335
   at net.r_eg.MvsSln.Core.IsolatedEnv.GetOrLoadProject(ProjectItem pItem, IDictionary`2 properties) in D:\prg\projects\MvsSln\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 210
   at net.r_eg.MvsSln.Core.IsolatedEnv.Load(IEnumerable`1 pItems) in D:\prg\projects\MvsSln\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 312
   at net.r_eg.MvsSln.Core.IsolatedEnv.LoadProjects(IEnumerable`1 pItems) in D:\prg\projects\MvsSln\MvsSln\MvsSln\Core\IsolatedEnv.cs:line 266
   at net.r_eg.MvsSln.Core.SlnParser.Parse(StreamReader reader, SlnItems type) in D:\prg\projects\MvsSln\MvsSln\MvsSln\Core\SlnParser.cs:line 154
   at net.r_eg.MvsSln.Core.SlnParser.Parse(String sln, SlnItems type) in D:\prg\projects\MvsSln\MvsSln\MvsSln\Core\SlnParser.cs:line 103
   at net.r_eg.MvsSln.Sln..ctor(String file, SlnItems type) in D:\prg\projects\MvsSln\MvsSln\MvsSln\Sln.cs:line 54
   at VsProjectStuff.Program.Main(String[] args) in C:\Users\Admin\Documents\Visual Studio 2017\Projects\VsProjectStuff\VsProjectStuff\Program.cs:line 14

Support SDK-based projects

The bug was described here: 3F/DllExport#56

For example, the following definition below should cause a problem as for #1:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>
</Project>
The default XML namespace of the project must be the MSBuild XML namespace or no namespace.

XProjectByFile() can destroy original properties that was prepared for solution

The essence of the error is as follows,

For some new instance of XProjectEnv with specific sln properties:

public XProjectEnv(ISlnResult data, IDictionary<string, string> properties, IDictionary<string, RawText> raw = null)
{
Sln = data ?? throw new ArgumentNullException(nameof(data));
rawXmlProjects = raw;
slnProperties = DefProperties(

*Using slnProperties we assume exactly sln properties.

Then, if we try to load the project that was not yet presented in collection, it will cause call XProjectByFile() with properties Configuration|Platform specified for this project. That's ok. However, it will also consider Configuration|Platform as a new pair for sln properties too.

This moment is possible whenever we need a call XProjectByFile(). It happens only when a specific project with the specific configuration has not yet been loaded at this point

if(found != null || !tryLoad || string.IsNullOrWhiteSpace(file)) {
return found;
}
var prj = GetOrLoadProject
(

And will cause error only if different cfg between sln and prj.

Create Solution Folder

Hello,

as far as I can see, I can't create new project folders or assign projects to folder. Our build system generates a flat list of 400 C++ projects and I want to categorize them.

Map not Refreshing

Hi,
I have a solution with over 500 projects and more than 10 build configurations. The goal is to delete all build configurations except for the two default ones, and to do the same for the projects. I have read through Issue #3, and I can successfully remove the data from the SLN. However, when I look at “Map”, all the configurations are still there, and are saved again accordingly. Is there a way to update this map ?

I have attached my Code to this Request and will be thankfull for your help.

using var sln = new Sln(openFileDialog1.FileName, SlnItems.AllNoLoad | SlnItems.PackagesConfig);

sln.Result.SolutionConfigs.ToList().ForEach(c =>
{
    if (!(c.Configuration == "Debug" && c.Platform == "Any CPU") && !(c.Configuration == "Release" && c.Platform == "Any CPU"))
        ((SlnResult)sln.Result).SolutionConfigList.Remove(c);
});

((SlnResult)sln.Result).ProjectConfigList.ToList().ForEach(c =>
{
    if(!(c.Configuration == "Debug" && c.Platform == "Any CPU") && !(c.Configuration == "Release" && c.Platform == "Any CPU"))
        ((SlnResult)sln.Result).ProjectConfigList.Remove(c);
});,

var whandlers = new Dictionary<Type, HandlerValue>();

using (var w = new SlnWriter(openFileDialog1.FileName, whandlers))
{
    w.Write(sln.Result.Map);
}

Kind regards,
Björn

Odd issue only when publishing via single file - Value cannot be empty string

Hi,

I'm experiencing a weird error that only happens when I publish my app as a single file. It seems to happen on deconstruction, which is odd. My goal is to load a list of solution configs and solution projects so that the user can choose an appropriate pair (config & project).

Here's the stack trace:

Unhandled exception. System.ArgumentException: The value cannot be an empty string. (Parameter 'path')
   at Microsoft.Build.Shared.BuildEnvironmentHelper.get_Instance()
   at Microsoft.Build.Utilities.Traits.get_Instance()
   at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties, IEnumerable`1 loggers, IEnumerable`1 remoteLoggers, ToolsetDefinitionLocations toolsetDefinitionLocations, Int32 maxNodeCount, Boolean onlyLogCriticalEvents, Boolean loadProjectsReadOnly)
   at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties, IEnumerable`1 loggers, IEnumerable`1 remoteLoggers, ToolsetDefinitionLocations toolsetDefinitionLocations, Int32 maxNodeCount, Boolean onlyLogCriticalEvents)
   at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties, IEnumerable`1 loggers, ToolsetDefinitionLocations toolsetDefinitionLocations)
   at Microsoft.Build.Evaluation.ProjectCollection..ctor(IDictionary`2 globalProperties)
   at Microsoft.Build.Evaluation.ProjectCollection..ctor()
   at Microsoft.Build.Evaluation.ProjectCollection.get_GlobalProjectCollection()
   at net.r_eg.MvsSln.Core.XProjectEnv.get_PrjCollection()
   at net.r_eg.MvsSln.Core.XProjectEnv.UnloadAll(Boolean throwIfErr)
   at net.r_eg.MvsSln.Core.IsolatedEnv.Dispose(Boolean _)
   at net.r_eg.MvsSln.Core.IsolatedEnv.Dispose()
   at net.r_eg.MvsSln.Sln.Dispose(Boolean _)
   at net.r_eg.MvsSln.Sln.Dispose()
   [MyApp stack trace here]

Here's the code in MyApp that the stack trace points to:

public static SolutionConfigPlatforms GetConfigurationsInSolution(DotnetProject solution)
{
    if (File.Exists(solution.FilePath))
    {
        using (var sln = new Sln(solution.FilePath, SlnItems.SolutionConfPlatforms | SlnItems.Env))
        {
            var output = new SolutionConfigPlatforms();
            output.DefaultConfig = sln.Result.DefaultConfig.Configuration;
            output.DefaultPlatform = sln.Result.DefaultConfig.Platform;
            foreach (var config in sln.Result.ProjectConfigs)
            {
                output.AddConfig(config.Configuration);
                output.AddPlatform(config.Platform);
            }
            return output; // <----- stack trace points here
        }
    }
    return new SolutionConfigPlatforms();
}

SolutionConfigPlatforms is a simple model defined as:

    class SolutionConfigPlatforms
    {
        public List<string> Configs { get; set; }
        public List<string> Platforms { get; set; }
        public string DefaultConfig { get; set; } // e.g. "Debug"
        public string DefaultPlatform { get; set; } // e.g. "AnyCPU"
         ...
     }

SLN:

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29709.97
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyApp.WPF", "MyApp.WPF\MyApp.WPF.csproj", "{83A590A7-F126-4FB2-8C94-4DF0ED16D5A5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyApp.Tests", "MyApp.Tests\MyApp.Tests.csproj", "{1F4289D8-3E67-46B1-B6B5-5368880F8969}"
EndProject
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "MyApp.Shared", "MyApp.Shared\MyApp.Shared.shproj", "{9A68665F-F039-49F2-903D-95EFBDA36C60}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MyApp.Avalonia", "MyApp.Avalonia\MyApp.Avalonia.csproj", "{C5C70FF0-E9ED-43AE-9CBC-1BF8CF60F37C}"
EndProject
Global
	GlobalSection(SharedMSBuildProjectFiles) = preSolution
		MyApp.Shared\MyApp.Shared.projitems*{83a590a7-f126-4fb2-8c94-4df0ed16d5a5}*SharedItemsImports = 5
		MyApp.Shared\MyApp.Shared.projitems*{9a68665f-f039-49f2-903d-95efbda36c60}*SharedItemsImports = 13
		MyApp.Shared\MyApp.Shared.projitems*{c5c70ff0-e9ed-43ae-9cbc-1bf8cf60f37c}*SharedItemsImports = 5
	EndGlobalSection
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{83A590A7-F126-4FB2-8C94-4DF0ED16D5A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{83A590A7-F126-4FB2-8C94-4DF0ED16D5A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{83A590A7-F126-4FB2-8C94-4DF0ED16D5A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{83A590A7-F126-4FB2-8C94-4DF0ED16D5A5}.Release|Any CPU.Build.0 = Release|Any CPU
		{1F4289D8-3E67-46B1-B6B5-5368880F8969}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{1F4289D8-3E67-46B1-B6B5-5368880F8969}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{1F4289D8-3E67-46B1-B6B5-5368880F8969}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{1F4289D8-3E67-46B1-B6B5-5368880F8969}.Release|Any CPU.Build.0 = Release|Any CPU
		{C5C70FF0-E9ED-43AE-9CBC-1BF8CF60F37C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{C5C70FF0-E9ED-43AE-9CBC-1BF8CF60F37C}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{C5C70FF0-E9ED-43AE-9CBC-1BF8CF60F37C}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{C5C70FF0-E9ED-43AE-9CBC-1BF8CF60F37C}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
	GlobalSection(ExtensibilityGlobals) = postSolution
		SolutionGuid = {01061048-C1F2-454F-9EA3-831A961CB95F}
	EndGlobalSection
EndGlobal

Note that this code runs on a background thread.

I haven't yet done the dirty work of trying to create a small minimal sample due to running out of time now, but am posting this in hopes that someone may know the answer or what to look at sooner than I will have time to dig in deeper. The issue seems to be deeper in MS-provided code, but am not sure if something is being utilized wrong.

Environment: macOS 12.6.9
.NET Version: .NET 8 RC 1 (this did seem to happen on .NET 7, too)

Build command: dotnet publish "/Users/[name]/Documents/Projects/[Name].csproj" --configuration "Release" --framework "net8.0" --runtime "osx-x64" /p:PublishSingleFile=true --self-contained True

Any help is appreciated!

Thanks~

ProjectGuid is obsolete and cannot guarantee a unique project instance

MS drops support of the ProjectGuid in their projects files.
Means that some project files may not provide this at all. And as a result, it cannot guarantee a uniqueness on this basis anymore.

3F/DllExport#36 (comment)
3F/vsSolutionBuildEvent#40

MvsSln still can provide a unique ProjectGuid because it uses data from .sln file and its project files.

However, it still will not guarantee a normal work with project instances through MBE.

Alternative is

Full path to project file is a unique identifier for today. Therefore, we need to review some parts of our code that was based on ProjectGuid when working with projects (some filters, collections, and so on).

Configurations and Projects/Colutions Oh My...

The VS GUI allows you do delete a Solution config, but that does not iterate through projects. I want to delete "ALL" project configurations and platforms except for a specific one...

I can iterate through them and identify them, but can not find the object to call a "remove like" method on...

var allprojectConfigs = data.ProjectItemsConfigs.ToList(); List<ProjectItemCfg> toRemove = new List<ProjectItemCfg>(); foreach (ProjectItemCfg projectConfig in allprojectConfigs) { if (projectConfig.projectConfig.Platform == "x64") { Microsoft.Build.Evaluation.Project loadedProject = sln.Result.Env.GetOrLoadProject(projectConfig.project); toRemove.Add(projectConfig); } } // OK, now kill everything in the "toRemove" list"

The SDK 'Microsoft.NET.Sdk' specified could not be found.

I am trying to add a project reference to a solution and this error message gets throw.

This is the code that throws the error.

sln.Result.Env.AddOrGet(new Project(XmlReader.Create(new StreamReader($@".\Solutions\{Namespace}\{Namespace}.Server\{Namespace}.Server.csproj"))));

I have net core sdk installed but couldn't figure out why this error occurs.

Removing EnvDTE features

net.r_eg.MvsSln.EnvDTE

Scheduled for removal in future major releases!

These features were added together with features from DllExport project when it was based on PowerShell scripts in the past (ie. obsolete today).

Today's MvsSln 2.x has been focused for work with data outside of Visual Studio IDE. And I don't see the future in the development of this thing for MvsSln.

Although it can be also separated into other independent project for more complex work with IDE/COM interop.

I want to hear some feedback for this. Because some other parts of related features already exists in vsSolutionBuildEvent + something new if it is in demand.

But anyway, I think this subset will no longer be as part of MvsSln.

[Bug] Inbuild MsBuild macro not recognized

Hey,
hope you are well!

When loading an sln with new Sln(@"C:\Users\JK\source\repos\path\to\my.sln", SlnItems.All & ~SlnItems.ProjectDependencies)

Following error occurs:
Microsoft.Build.Exceptions.InvalidProjectFileException: 'The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the expression in the Import declaration "\Microsoft.Cpp.Default.props" is correct, and that the file exists on disk. C:\Users\JK\source\repos\path\to\Client\Client.vcxproj'

I think its following statement, which is responsible in the vcxproj: <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

In vs, VCTargetsPath resolves to C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\VC\v160\ and not C:\

Is there any way for me to fix that issue or is it really a bug?

Sln wrapper review

sln.Result is a legacy from vssbe, no, mainly from its transferring from that projects.

In fact, we're using MvsSln through empty Sln class. That is, only as wrapper over initial vssbe parser with new r/w handlers etc.

MvsSln now is independent project, so we need to review this too. Anyway -_-

Variables in Project Files cause resolution failure...

Consider:

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

IF I simply load the solution, and then type to load the projects, "VSTargetsPath" seems to be empty as the project path resolves to "C:"....

Example on how to modify Sln files

Could you add a simple example of how to actually modify an .sln file? I am looking for something like, e.g. load an .sln file, search through the names of projects included in it, and remove one of these project inclusions, then save the .sln file again. How is this done?

Unfortunately, I failed to see any hint to that in the readme file. There is some talk about custom "handlers" that can apparently be used to write something, but all I am getting from the Sln object is a Results object with (read-only) enumerables.

Unlock public collections for modifications

Currently we're using some abstraction for enumeration of parsed items (projects, folders, dependencies, all others or most of this).

But v2 provides now analyzed map for some user modifications.

Basically,

Unlocking will give us more quick and convenient way for updating data. Because today's modifications mostly looks like extending its initial data, for example ~

var folders = new List<SolutionFolder>(sln.Result.SolutionFolders)

But to keep it clean, more probably we also need to provide some information about modified state if it was.

What about simply flag state via our wrapped collection ? where add/remove/or even changing value of available items will expose an dirty state after its initial parsing ?

Option 1

draft

  • Extract a common wrapper for existing enumerations.
  • This will provide an modified state after changing its collections.
  • Implement ICloneable interface to prevent shallow copying.
  • Something to reset or get the initial state of data.

Option 2

draft

  • Prepare intermediate wrapper for creating new write-handlers from result.

Please feedback before my some final decision!

ProjectSection(ProjectDependencies) is missing in .sln

When at least VS 16.5.4. Reported here https://developercommunity.visualstudio.com/content/problem/996183/projectsectionprojectdependencies-is-missing-in-sl.html

For MvsSln the problem affects ISlnPDManager ProjectDependencies feature (part of LProjectDependencies handler)

More like we need to add a compatible alternative to ProjectReference because actually it may be a new official behavior. Not sure, I'm waiting a reply, and moreover...

But anyway:

Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SlnTest1", "SlnTest1\SlnTest1.csproj", "{142CCFC4-AB0B-4680-9254-D22A669C337E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ClassLibrary1", "ClassLibrary1\ClassLibrary1.csproj", "{34EB954A-7FC0-4463-865D-8B353395B595}"
EndProject

While project file:

<ProjectReference Include="..\SlnTest1\SlnTest1.csproj">
  <Project>{142ccfc4-ab0b-4680-9254-d22a669c337e}</Project>
  <Name>SlnTest1</Name>
</ProjectReference>

Does anyone know anything about it?

Major changing for Guid (UUID) core processing. Moving up to Fnv-1a-128 based algorithms

Here, I was saying about Huid (-> Fnv-1a-128 (-> LX4Cnh)) which provides related fastest generating UUID in a .NET System.Guid compatible manner.

Today's MvsSln relies on MD5 (or SHA-1, edition for DllExport) when generating and comparing something from strings using Guid.

For example, XProject.PId and related Guid-like hashing

PId = CalculatePId(prj);
}
protected Guid CalculatePId(Project prj)
{
if(Project == null) {
return Guid.Empty;
}
return (
FindGuid(prj)
+ ProjectItem.projectConfig
+ ProjectItem.solutionConfig
)
.Guid();

This, of course, should not affect any well known Guids for VS/msbuild support. Only parts where must be generating a new one from input string. However, this invalidates the previously generated values which may require a complete re-evaluation in some cases.

Please feedback if this upgrading may cause problems and cannot be adapted in some used infrastructure etc.

Is there a way to identify a nuget reference?

Hello there,
I'm using this fantastic library and have a question, I'm parsing a csproj file. with something like this:

foreach (IXProject xp in sln.Result.Env.Projects)
                    {
...

and I want to identify which references are nuget or not, Is there a way to do that?
I'm using this

xp.GetItems("Reference")

but that instruction returns all references, including nuget ones but not sure how to identify in them on that list

Any help would be appreciated

Is there any good documentation???

Strugginly with something that should be simple (IMHO)... I have

var items = mvsProj.GetItems();

Now for each item (iteration is not the problem), how do I get to the file name???

I feel bad asking these questions as they are not "issues..... But some documentation beyond what is on the start page (or downloading an understanding the source) should be great .... hopefully I am just missing something obvious.)

(note, the best I could come up was filtering on the "type" property...

The format `Debug` of configuration is not supported

3F/DllExport#114

The problem is that some plugins can avoid an platform records at all:

GlobalSection(ProjectConfigurationPlatforms) = postSolution
    {CDCFC754-DC29-4F73-A4B1-C9427BD43D0D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
    {CDCFC754-DC29-4F73-A4B1-C9427BD43D0D}.Debug|Any CPU.Build.0 = Debug|Any CPU
    {CDCFC754-DC29-4F73-A4B1-C9427BD43D0D}.Release|Any CPU.ActiveCfg = Release|Any CPU
    {CDCFC754-DC29-4F73-A4B1-C9427BD43D0D}.Release|Any CPU.Build.0 = Release|Any CPU
    {C44BFE7A-DBED-411A-8073-C88663B18ADC}.Debug|Any CPU.ActiveCfg = Debug
    {C44BFE7A-DBED-411A-8073-C88663B18ADC}.Release|Any CPU.ActiveCfg = Release
EndGlobalSection

Debug|Any CPU.ActiveCfg = Debug is not valid for current processing

/// {A7BF1F9C-F18D-423E-9354-859DC3CFAFD4}.Debug.x64.x86|Any.CPU.etc.Build.0 = Debug.x64.x86|Any.CPU.etc
/// \___________________________________/ \___________/ \_________/ \_____/ ^ \___________/ \_________/
///

WProject does not work on Linux

When writing solution file using the WProject handler the file is not correctly written on Linux systems.
WVisualStudioVersion seems to have the same problem.

This is probably because on Linux the AppendLine does add only LF instead of CR + LF.
WProject simply cuts off two characters.

<ItemGroup>add .cs files and embedded resources

I want to add some c# files and folders to .csproj file:

<Compile Include="financial\Invoice.cs" />
<Compile Include="financial\Invoice.Designer.cs">
  <DependentUpon>Invoice.cs</DependentUpon>
</Compile>

also I want to add some embedded resource:


  <ItemGroup>
    <EmbeddedResource Include="Images\Images.Invoice.png" />

Is it possible with your library? if yes, how?

Regards

Sequence contains no elements

"Sequence contains no elements" problem was already fixed in 2.3. Just found this together with #19

Can be reproduced via DllExport 1.6.3 (that uses MvsSln 2.2) and steps from: 3F/DllExport#114

TODO: add info into changelog

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.