smartstore / Smartstore

A modular, scalable and ultra-fast open-source all-in-one eCommerce platform built on ASP.NET Core 7
http://www.smartstore.com/
GNU Affero General Public License v3.0
1.2k stars 447 forks source link

AddRazorRuntimeCompilation not working VS Version 17.10.1 #1112

Closed suatsuphi closed 5 months ago

suatsuphi commented 5 months ago

Hello,

The changes I made in the razor view do not work in debugging. I think the reason is due to the visual studio version. this error occurred after updating!

what is your comment?

Microsoft Visual Studio Community 2022 (64-bit) - Current Version 17.10.1

suatsuphi commented 5 months ago

Version 17.10.2 razor problem fixed... it is working now

I wrote a program like the following for my own test environment

using System;
using System.Diagnostics;
using System.IO;
using System.Media;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Windows.Forms.VisualStyles;

namespace VS_Shortcut
{
    public partial class Form1 : Form
    {
        // Windows API fonksiyonlarını tanımlayın
        [DllImport("user32.dll", SetLastError = true)]
        private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);

        private void SelectVS()
        {
            Process[] processes = Process.GetProcessesByName("devenv");
            foreach (Process process in processes)
            {
                // Eğer işlem ana pencere tanıtıcısına sahipse pencereyi öne getir
                if (process.MainWindowHandle != IntPtr.Zero)
                {
                    SetForegroundWindow(process.MainWindowHandle);
                    break; // İlk bulunan pencereyi öne getirdikten sonra döngüyü kır
                }
            }
        }

        private void SelectEdgeWindow()
        {
            Process[] processes = Process.GetProcessesByName("msedge");
            foreach (Process process in processes)
            {
                // Eğer işlem ana pencere tanıtıcısına sahipse pencereyi öne getir
                if (process.MainWindowHandle != IntPtr.Zero)
                {
                    SetForegroundWindow(process.MainWindowHandle);
                    break; // İlk bulunan pencereyi öne getirdikten sonra döngüyü kır
                }
            }
        }

        public Form1()
        {
            InitializeComponent();
        }

        static void stop()
        {
            // iisexpress.exe işlemini sonlandırma
            Process[] iisProcesses = Process.GetProcessesByName("iisexpress");
            foreach (Process process in iisProcesses)
            {
                process.Kill();
            }

            string windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
            string soundFilePath = Path.Combine(windowsFolder, "Media", "Windows Notify.wav");
            SoundPlayer player = new SoundPlayer(soundFilePath);
            player.Play();
        }

        private int normalWidth;
        private int x;
        private int y;
        private void Form1_Load(object sender, EventArgs e)
        {
            Form form = (Form)sender;
            form.TopMost = true;
            FormBorderStyle = FormBorderStyle.FixedDialog;
            this.FormBorderStyle = FormBorderStyle.None;

            // Ekranın sağ alt köşesinin koordinatlarını al
            x = Screen.PrimaryScreen.WorkingArea.Right - this.Width;
            y = Screen.PrimaryScreen.WorkingArea.Bottom - this.Height;

            // Formun konumunu belirle
            this.Location = new Point(x, y);
            //

            //this.normalWidth = this.Width;
            //this.Width = 40;

        }

        static void play(bool ctrlF5 = true)
        {
            try
            {
                stop();

                string source = @"C:\Users\USERFOLDER\source\repos\Smartstore\src\Smartstore.Modules\Smartstore.BT";
                string destination = @"C:\Users\USERFOLDER\source\repos\Smartstore\src\Smartstore.Web\Modules\Smartstore.BT";

                // Hedef dizinindeki dosyaları silme
                if (Directory.Exists(destination))
                {
                    Directory.Delete(destination, true);
                }

                // Hedef dizinindeki Localization, Views ve wwwroot klasörlerini oluşturma
                string[] subdirectories = { "Localization", "Views", "wwwroot" };
                foreach (string subdir in subdirectories)
                {
                    Directory.CreateDirectory(Path.Combine(destination, subdir));
                }

                // Localization, Views ve wwwroot klasörlerini kopyalama
                string[] directoriesToCopy = { "Localization", "Views", "wwwroot" };
                foreach (string dir in directoriesToCopy)
                {
                    string sourceDir = Path.Combine(source, dir);
                    string destinationDir = Path.Combine(destination, dir);
                    CopyDirectory(sourceDir, destinationDir);
                }

                // Smartstore.BTdosyalarını kopyalama
                string[] filesToCopy = { "Smartstore.BT.dll", "Smartstore.BT.pdb" };
                foreach (string file in filesToCopy)
                {
                    string sourceFile = Path.Combine(source, "obj", "BTDebug", file);
                    string destFile = Path.Combine(destination, file);
                    File.Copy(sourceFile, destFile, true);
                }

                // module.json dosyasını kopyalama
                string moduleJsonSource = Path.Combine(source, "module.json");
                string moduleJsonDest = Path.Combine(destination, "module.json");
                File.Copy(moduleJsonSource, moduleJsonDest, true);

                Console.WriteLine("Kopyalama tamamlandı.");
                Console.WriteLine("CTRL + F5 tuş kombinasyonu gönderiliyor...");

                // Visual Studio'yu bulma ve CTRL + F5 gönderme
                Process[] processes = Process.GetProcessesByName("devenv");
                if (processes.Length > 0)
                {
                    IntPtr handle = processes[0].MainWindowHandle;
                    SetForegroundWindow(handle);
                    if (ctrlF5)
                        System.Windows.Forms.SendKeys.SendWait("^{F5}");
                    else
                        System.Windows.Forms.SendKeys.SendWait("{F5}");

                    Console.WriteLine("CTRL + F5 tuş kombinasyonu gönderildi.");
                }
                else
                {
                    Console.WriteLine("Visual Studio bulunamadı.");
                }

                string windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
                string soundFilePath = Path.Combine(windowsFolder, "Media", "Speech On.wav");

                SoundPlayer player = new SoundPlayer(soundFilePath);
                player.Play();

                //Thread.Sleep(1000);
                //this.Close();
            }
            catch (Exception ex)
            {
                string windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
                string soundFilePath = Path.Combine(windowsFolder, "Media", "Windows Critical Stop.wav");
                SoundPlayer player = new SoundPlayer(soundFilePath);
                player.Play();
                MessageBox.Show("Bir hata oluştu: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

        }

        // Klasör kopyalama fonksiyonu
        static void CopyDirectory(string sourceDir, string targetDir)
        {
            if (!Directory.Exists(targetDir))
            {
                Directory.CreateDirectory(targetDir);
            }

            foreach (string file in Directory.GetFiles(sourceDir))
            {
                string dest = Path.Combine(targetDir, Path.GetFileName(file));
                File.Copy(file, dest, true);
            }

            foreach (string subdir in Directory.GetDirectories(sourceDir))
            {
                string dest = Path.Combine(targetDir, Path.GetFileName(subdir));
                CopyDirectory(subdir, dest);
            }
        }

        // SetForegroundWindow fonksiyonu
        [System.Runtime.InteropServices.DllImport("user32.dll")]
        static extern bool SetForegroundWindow(IntPtr hWnd);

        private void btnPlay_Click(object sender, EventArgs e)
        {
            play();
            Thread.Sleep(1000);
            SelectEdgeWindow();
        }

        private void btnStop_Click(object sender, EventArgs e)
        {
            stop();
            Thread.Sleep(1000);
            SelectVS();
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            string windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
            string soundFilePath = Path.Combine(windowsFolder, "Media", "Windows Logoff Sound.wav");
            SoundPlayer player = new SoundPlayer(soundFilePath);
            player.Play();
            Thread.Sleep(1000);
        }

        private void btnDebug_Click(object sender, EventArgs e)
        {
            try
            {
                btnPlay.Enabled = false;
                btnStop.Enabled = false;
                stop();
                // Visual Studio'yu bulma ve CTRL + F5 gönderme
                Process[] processes = Process.GetProcessesByName("devenv");
                if (processes.Length > 0)
                {
                    IntPtr handle = processes[0].MainWindowHandle;
                    SetForegroundWindow(handle);
                    System.Windows.Forms.SendKeys.SendWait("+{F6}");
                    //Console.WriteLine("CTRL + F5 tuş kombinasyonu gönderildi.");
                    string windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
                    string soundFilePath = Path.Combine(windowsFolder, "Media", "Windows Information Bar.wav");
                    SoundPlayer player = new SoundPlayer(soundFilePath);
                    player.Play();
                    //
                }
                else
                {
                    //Console.WriteLine("Visual Studio bulunamadı.");
                }
            }
            catch (Exception ex)
            {
                string windowsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Windows);
                string soundFilePath = Path.Combine(windowsFolder, "Media", "Windows Critical Stop.wav");
                SoundPlayer player = new SoundPlayer(soundFilePath);
                player.Play();
                MessageBox.Show("Bir hata oluştu: " + ex.Message, "Hata", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                btnPlay.Enabled = true;
                btnStop.Enabled = true;
            }

        }

        private void btnFolder_Click(object sender, EventArgs e)
        {
            string folderPath = @"C:\Users\USERFOLDER\source\repos\Smartstore\src\Smartstore.Web\App_Data";
            Process.Start("explorer.exe", folderPath);
        }

        private void btnSQLite_Click(object sender, EventArgs e)
        {
            string filePath = @"C:\Users\USERFOLDER\source\repos\Smartstore\src\Smartstore.Web\App_Data\Tenants\Default\WebStoreDB.db";

            Process.Start(new ProcessStartInfo
            {
                FileName = filePath,
                UseShellExecute = true
            });
        }

        private void btnBT_Click(object sender, EventArgs e)
        {
            string folderPath = @"C:\Users\USERFOLDER\source\repos\Smartstore\src\Smartstore.Modules";
            Process.Start("explorer.exe", folderPath);
        }

        private void btnF5_Click(object sender, EventArgs e)
        {
            play(false);
            Thread.Sleep(1000);
            SelectEdgeWindow();
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}