簡體   English   中英

如何在VSCode中使用調試/發布移動引用的DLL?

[英]How do i move referenced DLLs with debug/release in VSCode?

設定

我將一個C#VS2015控制台應用程序項目轉換為VSCode,並嘗試添加DLL引用並在構建時移動任何引用的DLL。

首先, Dotnet add package The project does not support adding package references through the add package command.正常工作,錯誤The project does not support adding package references through the add package command. 所以我手動將項目添加到.csproj文件中。 我要添加的軟件包是本地版本,位於./Lib/AutoItX

Lib/
   └── AutoItX
        ├── AutoItX3_x64.dll
        ├── AutoItX3.Assembly.dll
        ├── AutoItX3.Assembly.xml
        └── AutoItX3.dll

添加到.csprog

<ItemGroup>
    <Reference Include="AutoItX">
      <HintPath>.\Lib\AutoItX\AutoItX3.Assembly.dll</HintPath>
    </Reference>
  </ItemGroup>

參考工作,如果我手動將DLL移動到Debug文件夾,它會找到它,一切都很好。

有沒有辦法自動將DLL移動到文件夾中?

目前,在全新運行后,我的調試文件夾如下所示:

bin/
   └── x64
        └── Debug
            ├── AutoItX3.Assembly.dll
            ├── AutoItX3.Assembly.xml
            ├── Application.exe
            ├── Application.exe.config
            └── Application.pdb

我想在x64版本中自動包含AutoItX3_x64.dll ,如果可能的AutoIt3.dll ,x86版本中包含AutoIt3.dll (它目前沒有為x86版本設置,我只想知道如何)

附加信息

我的launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": ".NET Core Launch (console)",
            "type": "clr",
            "request": "launch",
            "preLaunchTask": "compile",
            "program": "${workspaceFolder}/Application/bin/x64/Debug/StartApplication.exe",
            "args": ["./Download/start.json"],
            "cwd": "${workspaceFolder}",
            "console": "externalTerminal",
            "stopAtEntry": false
        },
        {
            "name": ".NET Core Attach",
            "type": "clr",
            "request": "attach",
            "processId": "${command:pickProcess}"
        }
    ]
}

我的tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "compile",
            "type": "shell",
            "command": "dotnet",
            "args": [
                // Ask msbuild to generate full paths for file names.
                "msbuild",
                "Application.sln",
                "/property:GenerateFullPaths=true",
                "/property:Platform=x64"
            ],
            "group": "build",
            "presentation": {
                // Reveal the output only if unrecognized errors occur.
                "reveal": "silent"
            },
            // Use the standard MS compiler pattern to detect errors, warnings and infos
            "problemMatcher": "$msCompile"
        }
    ]
}

Application.sln


Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Application", "Application\Application.csproj", "{E9AA3396-3EAD-47EE-9927-F20D87B34BF6}"
EndProject
Global
    GlobalSection(SolutionConfigurationPlatforms) = preSolution
        Debug|Any CPU = Debug|Any CPU
        Debug|x86 = Debug|x86
        Debug|x64 = Debug|x64
        Release|Any CPU = Release|Any CPU
        Release|x86 = Release|x86
        Release|x64 = Release|x64
    EndGlobalSection
    GlobalSection(ProjectConfigurationPlatforms) = postSolution
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|Any CPU.Build.0 = Debug|Any CPU
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x86.ActiveCfg = Debug|x86
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x86.Build.0 = Debug|x86
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x64.ActiveCfg = Debug|x64
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Debug|x64.Build.0 = Debug|x64
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|Any CPU.ActiveCfg = Release|Any CPU
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|Any CPU.Build.0 = Release|Any CPU
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x86.ActiveCfg = Release|x86
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x86.Build.0 = Release|x86
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x64.ActiveCfg = Release|x64
        {E9AA3396-3EAD-47EE-9927-F20D87B34BF6}.Release|x64.Build.0 = Release|x64
    EndGlobalSection
    GlobalSection(SolutionProperties) = preSolution
        HideSolutionNode = FALSE
    EndGlobalSection
EndGlobal

我所知道的和我嘗試過的

microsofts docs顯示你可以使用metatag <DependentUpon> ,我試過沒有運氣。
文檔還提到了在.csproj中使用了else-ware的條件 ,這讓我覺得一旦我有一個有效的配置,我就可以創建條件使其適用於兩個平台。
似乎可以解決這個特定問題的另一件事是任務 ,但這感覺非常強大,我不知道如何解析所有外部本地DLL移動的.csproj

這篇文章真的有助於解釋如何鏈接內容。

<ItemGroup>
  <Content Include="..\Shared\SharedSettings.json" Link="SharedSettings.json" CopyToOutputDirectory="PreserveNewest" />
</ItemGroup>

通過使用問題中鏈接文檔的條件,我能夠分別移動x86和x64的DLL。

這是.csproj的最終解決方案

<ItemGroup>
    <Reference Include="AutoItX">
      <HintPath>$(ProjectDir)\Lib\AutoItX\AutoItX3.Assembly.dll</HintPath>
    </Reference>
    <Content Include="$(ProjectDir)\Lib\AutoItX\AutoItX3_x64.dll" Condition="'$(Platform)' == 'x64'" Link="AutoItX3_x64.dll" CopyToOutputDirectory="PreserveNewest" />
    <Content Include="$(ProjectDir)\Lib\AutoItX\AutoItX3.dll" Condition="'$(Platform)' == 'x86'" Link="AutoItX3.dll" CopyToOutputDirectory="PreserveNewest" />
  </ItemGroup>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM