why spark files not included in publishe folder? - asp.net-mvc

I tried file system publish and ftp
I'm using VS2010 and .net 4.0
should i somehow include *.spark ext files to the MSBuild?

See this. You basically have to set .spark files' Build Action to Content.
Here's a macro to do so:
Sub SetSparkBuildAction(ByVal scope As EnvDTE.vsBuildScope, ByVal action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
For Each proj As Project In DTE.Solution.Projects
RecurseSetSparkBuildAction(proj)
Next
End Sub
Sub RecurseSetSparkBuildAction(ByVal item As Object)
If (item.Name.EndsWith(".spark", StringComparison.CurrentCultureIgnoreCase)) Then
item.Properties.Item("BuildAction").Value = 2
End If
For Each childItem As ProjectItem In item.ProjectItems
RecurseSetSparkBuildAction(childItem)
Next
End Sub
To use this macro, open up Macros IDE (Alt+F11), locate EnvironmentEvents in a leftmost treeview and paste this code outside of the "Automatically generated code, do not modify" region.

Related

Calling Another Project's Controller From A Project In The Same Solution (.NET Core )

There are 2 projects in the same solution. First project is a .NET Core project and it has all the codes(controllers, models etc.) related to packages. I need to get the information (id, name, description) of the packages and display it in the second project(.NET Core Web App with Razor). Is it possible to do it without changing the first project? I only want to show the package list on a single web page.
I tried calling the first project's controller but it didn't work. Maybe I missed a point. Any help is appreciated.
This requirement can be achieved, please see the gif image below.
Tips
If you want to call another project's controller from a project in the same solution, you need to make sure there is in HomeController in both project. I mean the name of any class should be unique in both projects.
Otherwise you will face the same issue like my homepage.
Test Code:
public List<PackageReference> GetPackageList5(string projectname)
{
List<PackageReference> list = new List<PackageReference>();
PackageReference p = null;
XDocument doc = XDocument.Load(_webHostEnvironment.ContentRootPath+ "/"+ projectname + ".csproj");
var packageReferences = doc.XPathSelectElements("//PackageReference")
.Select(pr => new PackageReference
{
Include = pr.Attribute("Include").Value,
Version = pr.Attribute("Version").Value
});
Console.WriteLine($"Project file contains {packageReferences.Count()} package references:");
foreach (var packageReference in packageReferences)
{
p = new PackageReference();
p.Version= packageReference.Version;
p.Include= packageReference.Include;
list.Add(packageReference);
//Console.WriteLine($"{packageReference.Include}, version {packageReference.Version}");
}
return list;
}
My Test Steps:
create two project, Net5MVC,Net6MVC
add project reference.
My .net6 project references a .net5 project. So in my HomeController (.net), I add below:
using Net5MVC.ForCore6;
using Net5MVC.Models;
Suggestion
When we reference the .net5 project in .net6 project, we can build success, but when we deploy it, it always failed. The reason is some file was multiple publish output files with the same relative path.
Found multiple publish output files with the same relative path:
D:\..\Net6\Net6\Net5MVC\appsettings.Development.json,
D:\..\Net6\Net6\Net6MVC\appsettings.Development.json,
D:\..\Net6\Net6\Net5MVC\appsettings.json,
D:\..\Net6\Net6\Net6MVC\appsettings.json.
And usually will add class library to current project, not add a web project.
As we know we can find packages info in .csproj file, so we need copy and paste .csproj file to publish folder.
I still recommend using the GetPackageList5 method above as an interface for your project, using HttpClient for requests.

Visual Studio macro to navigate to T4MVC link

I use T4MVC and I'm happy with it and want to keep it - it keeps down run time defects. Unfortunately, it makes it harder to navigate to views and content (a.k.a. Views and Links in T4MVC) though. Even using Resharper, I can't navigate to the referenced item:
T4MVC and Resharper Navigation
Can I get a hand building a macro to do this? Never having built a VS IDE macro before, I don't have a grasp on how to get at some things, like the internal results of the "Go To Definition" process, if that's even possible.
If you aren't familiar with T4MVC, here's generally what the macro might do to help:
Given the token: Links.Content.Scripts.jQuery_js in the file MyView.cshtml, '(F12) Go To Definition'. This behaves properly.
Having arrived at the the related assignment:
public readonly string jQuery_js = "~/Content/Scripts/jQuery.js"; in a file generated by T4MVC (which is very nice, thank you David, but we really don't ever need to see), capture the string assigned and close the file.
Navigate in Solution Explorer to the PhysicalPath represented by the captured string.
This process would also work for views/layouts/master-pages/partials, etc.
If you provide a macro or link to a macro to do this, or have another solution, wonderful. Otherwise, hints on how to do step 3 simply in a VS macro would be especially appreciated and receive upvote from me. I'd post the macro back here as an answer when done.
Thanks!
Here's a Visual Studio macro to help.
What it does
Now you probably use T4MVC references in places like this:
Layout = MVC.Shared.Views.MasterSiteTheme;
ScriptManager.AddResource(Links.Content.Script.jQueryXYZ_js);
<link type="text/css" href="#Links.Content.Style.SiteTheme_css" />
return View(MVC.Account.Views.SignIn);
#Html.Partial(MVC.Common.Views.ContextNavigationTree)
#Html.ActionLink("Sign in / Register", MVC.Account.SignIn())
F12 (Go to Definition) already works for the last bullet (actions), but this hack is intended to cover the other scenarios (resources).
Macro
Imports EnvDTE
Imports System.IO
Public Module NavT4Link
Sub NavigateToLink()
DTE.ExecuteCommand("Edit.GoToDefinition")
Dim navpath As String = Path.GetFileName(DTE.ActiveDocument.FullName)
Dim isContentLink As Boolean = navpath.Equals("T4MVC.cs")
If (isContentLink Or navpath.EndsWith("Controller.generated.cs")) Then
Dim t4doc As TextDocument = DTE.ActiveDocument.Object()
navpath = CurrentLinePathConstant(t4doc)
If isContentLink Then
t4doc.Selection.MoveToPoint(t4doc.Selection.ActivePoint.CodeElement(vsCMElement.vsCMElementClass).StartPoint)
t4doc.Selection.FindText("URLPATH")
navpath = Path.Combine(CurrentLinePathConstant(t4doc), navpath)
End If
If navpath.StartsWith("~") Then
DTE.ActiveDocument.Close(vsSaveChanges.vsSaveChangesPrompt)
Dim proj As Object = DTE.Solution.FindProjectItem(DTE.ActiveDocument.FullName).ContainingProject
navpath = Path.GetDirectoryName(proj.Fullname()) + navpath.TrimStart("~")
DTE.ItemOperations.OpenFile(navpath)
End If
End If
End Sub
Function CurrentLinePathConstant(ByVal t4doc As TextDocument) As String
t4doc.Selection.SelectLine()
Dim sa() As String = t4doc.Selection.Text().Split("""")
If sa.Length > 1 Then Return sa(sa.Length - 2) Else Return ""
End Function
End Module
Installation
In Visual Studio, press "Alt-F8" to open Macro Explorer.
Right-Click "My Macros", select "New Module...", and click "Add".
Replace all the text with the code shown here.
Save and exit the Macro Editor.
Open "Tools : Options".
In the left pane, select "Environment : Keyboard".
In the "Show commands containing" text field enter "T4".
In the "Press shortcut keys:" field press the "F12" key.
Click "Assign" and "OK".
On un-patched VS, this installation process doesn't result in a 'bindable' macro. A workaround was to (CTRL-SHIFT-R-R) to record an empty macro, and paste the code into it without renaming it. If someone knows of a more documentable approach to install a macro in VS, please comment.
Notes/Caveats
It's meant to replace the current F12 functionality, so if it isn't a T4MVC link, it will do the usual, otherwise it continues on to open the resource. It handles the majority of cases, but not T4MVC-generated empty controller methods. Those you get dumped off at the same place you did before.
For Content/Asset/Link resources, navigating to it in Solution Explorer would probably be in order, for image files for example, but I didn't see that functionality in the Visual Studio docs.

How can I create a directory in my source control using TFS 2010 SDK?

I want to customize the creation of a TFS project using TFS 2010 SDK.
I have already create a process template and use this sample, but I want to create a specific directory tree for the new team project base on a XML file which describe the tree. My problem is this message; The array must contain at least one element.
Parameter name: checkinParameters.PendingChanges
I initialize the TFS, map the server folder with a local folder and create directories in both.
fooString = Array.Find<WorkingFolder>(workspace.Folders, m => m.ServerItem.Contains("$/FR_DEV"));
Directory.CreateDirectory(ElementPath);
Directory.CreateDirectory(fooString.ServerItem + ElementTfsPath);
After that:
PendingChange[] PendingChanges = workspace.GetPendingChanges();
// Checkin the items we added
int changesetForAdd = workspace.CheckIn(PendingChanges, "Project creation.");
However, I get an error for the pending change! How can I fix this?
my problem was that i need to add the directory in the workspace not with a simple path
workspace.PendAdd(currentSubDirectory, true);

Programmatically Add Files To TFS with dependency files

How can I programmatically add files to a TFS project that have code behind files. I can say the following to add files. That will only add single files to a project and not the file plus the code behind file. I'm trying to add a resource file and it's code behind that were dynamically generated to a TFS project.
workspace.PendAdd(filesWithPathToEdit, true);
I had to put it in a T4 template to get access to the current Visual Studio DTE otherwise it would randomly work if I tried it outside of a t4. You can use the DTE to get a list of projects from a solution then add a ProjectItem and it contains ProjectItems so you can add your code behind there. ResxContainer is a custom class to just contain all information about my resx file i needed.
EnvDTE.DTE dte = (EnvDTE.DTE)HostServiceProvider.GetService(typeof(EnvDTE.DTE));
//dte = (EnvDTE.DTE) hostServiceProvider.GetService(typeof(EnvDTE.DTE));
//dte = (EnvDTE80.DTE2)Marshal.GetActiveObject("VisualStudio.DTE");
Projects projects = dte.Solution.Projects;
if (projects.Count > 0)
{
IEnumerator enumer = ((IEnumerable)projects).GetEnumerator();
while (enumer.MoveNext())
{
Project proj = (Project)enumer.Current;
if (proj.Name == projectName)
{
foreach (ResxContainer res in items)
{
ProjectItem item = proj.ProjectItems.AddFromFile(res.ResxPath);
item.ProjectItems.AddFromFile(res.CodeBehindPath);
}
}
}
There's no way for it to automatically know if a file depends on another. However, you can decide on your own which files will typically have a code behind file associated with them and add them yourself.
For example:
If you begin to add a file with an .aspx extension, then those files, as we know, typically have a code behind file. That code behind file, we can assume, has the same file name, with .cs appended. So, if we have "Default.aspx", then we can safely assume that there will be a "Default.aspx.cs" and that they are dependent on each other, so we should add both.
The same thing goes with .xaml and .xaml.cs files.

Delphi: How to set the default project in a project group?

i have two projects in a project group:
ProjectA
ProjectB
Whenever i open the ProjectGroup.bpg in Delphi, it always starts with the 2nd project as the active one:
ProjectA
ProjectB
And every time i have to flip it to the the "real" project:
ProjectA
ProjectB
How can i make ProjectA the default project that opens with the project group?
ProjectGroup.bpg
#------------------------------------------------------------------------------
VERSION = BWS.01
#------------------------------------------------------------------------------
!ifndef ROOT
ROOT = $(MAKEDIR)\..
!endif
#------------------------------------------------------------------------------
MAKE = $(ROOT)\bin\make.exe -$(MAKEFLAGS) -f$**
DCC = $(ROOT)\bin\dcc32.exe $**
BRCC = $(ROOT)\bin\brcc32.exe $**
#------------------------------------------------------------------------------
PROJECTS = ProjectA.exe ProjectB.exe
#------------------------------------------------------------------------------
default: $(PROJECTS)
#------------------------------------------------------------------------------
ProjectA.exe: ProjectA.dpr
$(DCC)
ProjectB.exe: childfolder\ProjectB.dpr
$(DCC)
See DUnit: How to run unit tests for the practical reason.
Far from ideal but the only way I know is like
in the Delphi IDE, right click your default project in the Project Manager and select Build Later.
or Switch the lines for Project A and Project B in the .bpg file.
You might have a stuck desktop settings file. Look for a .DSK file associated with your project group, and delete it.
In Delphi 7 (and I presume later also) you can select the 'active' project in the project group tree by double-clicking it. If you then do 'Save Project Group As' by right clicking the top of the project tree, the active project is saved with the group and will open at that when you next open the project group.
Place file ProjectGroup.dsk in project folder with text:
[ActiveProject]
ActiveProject=1
or set check to TRUE in Environment Options -> Preferences -> Autosave Options -> Project Desktop, this will create DSK files for projects and groups automatic!

Resources