(C#)Signalr 2.2.2-从VS(SUB 2017)转移到VS 2017的项目发行



因此,事实证明,Microsoft提供了一个有关如何制作Web应用程序的教程/sigralr/概述/启动/tutorial-getting-with-signalr#设置

设置似乎很简单,但是当涉及哪个版本的代码与最新更新兼容时,这很棘手。我要提到的一件事是启用了提示,要求用户输入其名称。为了做到这一点,我用以下方式替换给定HTML代码:

<title>SignalR Simple Chat</title>
<style type="text/css">
    .container {
        background-color: #99CCFF;
        border: thick solid #808080;
        padding: 20px;
        margin: 20px;
    }
</style>

<div class="container">
    <input type="text" id="message" />
    <input type="button" id="sendmessage" value="Send" />
    <input type="hidden" id="displayname" />
    <ul id="discussion"></ul>
</div>
<script src="scripts/jquery-1.6.4.js"></script>
<script src="scripts/jquery.signalR-2.2.2.js"></script>

<!--Add script to update the page and send messages.-->
<script type="text/javascript">
    $(function () {

        var connection = $.hubConnection();
        var chat = connection.createHubProxy('chatHub');
        // Declare a proxy to reference the hub.
        //var chat = $.connection.chatHub;
        // Create a function that the hub can call to broadcast messages.
        chat.on('broadcastMessage', function (name, message) {
            // Html encode display name and message.
            var encodedName = $('<div />').text(name).html();
            var encodedMsg = $('<div />').text(message).html();
            // Add the message to the page.
            $('#discussion').append('<li><strong>' + encodedName
                + '</strong>:  ' + encodedMsg + '</li>');
        });
        // Get the user name and store it to prepend to messages.
        $('#displayname').val(prompt('Enter your name:', ''));
        // Set initial focus to message input box.
        $('#message').focus();

        connection.start(function () {
            $('#sendmessage').click(function () {
                // Call the Send method on the hub.

                chat.invoke('Send', $('#displayname').val(), $('#message').val());
                // Clear text box and reset focus for next comment.
                $('#message').val('').focus();
            });

        });
    });
</script>

,就弹出窗口而言,这似乎是做到的。但是,就显示框上的用户看到的实际输出,按下发送按钮时看不到。另外,新的HTML代码似乎允许VS 2017程序员单击"发送"按钮时清除聊天框。谁能找出此简单应用程序中可能不是最新的?

这可能是SignalR或其他内容的更新问题...

我不知道这是否是您的情况,我的答案是否会解决您的问题,但是看来VS 2017中创建的项目包含csproj文件中的以下说明:

<PropertyGroup>
    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)MicrosoftVisualStudiov$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>

绊倒了类似的错误后,一旦我手动将上述指令添加到现有的csproj文件中,我的项目最终设法加载了VS 2017

要详细说明,请在csproj文件中找到以下文本(定义导入Web应用程序目标):

<Import Project="$(VSToolsPath)WebMicrosoft.Web.Publishing.targets" Condition="'$(VSToolsPath)' != ''" />

并将指令放在其前。

最新更新