c++ – How to make boost::python use the Python embeddable package


I’m currently working on a 32-bit C++ DLL in Visual Studio 2022 which uses boost::python to embed Python code. For my builds I use the include and lib directories from a full installation of 32-bit Python on my machine, as the Python embeddable package doesn’t ship with these header or lib files. However when actually running I want it to use the interpreter in the embeddable package. I think this should be as simple as getting it to open the Python312.dll file from inside the embeddable package directory, however I can’t figure ou how to make it not prefer the DLL from the full python installation on my PATH. I have tried explicitly loading the DLL with LoadLibrary, but I think boost::python is already implicitly linked with the other DLL which takes precedence. Is there something I’m missing here? Please let me know if you need any more information, thanks.

Effortless publishing to Azure WebJobs on Linux


Are you tired of the cumbersome process involved in publishing your .NET console applications to Azure WebJobs on Linux? For developers yearning for a seamless and efficient method to deploy their applications, Visual Studio 2022 introduces a much-anticipated solution.

Publish to specific target Linux

Visual Studio 2022 now supports right-click publishing to Azure WebJobs on Linux, making the deployment process faster and more intuitive than ever before. This new feature brings much-needed convenience to developers working with cross-platform .NET 5.0+ Console Apps, allowing them to effortlessly publish their code with just a few clicks.

Why This Matters: The Problem at Hand

Deploying applications to Azure WebJobs on Linux traditionally required several manual steps, often leading to inefficiencies and increased potential for errors. Developers faced a fragmented workflow, which could be time-consuming and prone to mistakes, ultimately impacting project timelines and productivity.

The Solution: Simplified Publishing Process

With the right-click publish feature in Visual Studio 2022, the deployment process has been streamlined significantly. Here’s how it benefits you:

Ease of Use: Simply right-click on your project in Visual Studio and select the option to publish to Azure WebJobs on Linux. The intuitive interface guides you through the process, reducing the complexity and time required for deployment.

Cross-Platform Compatibility: This feature supports .NET 5.0+ Console Apps, ensuring that your applications are compatible across various platforms, enhancing their versatility and reach.

Enhanced Efficiency: By minimizing manual steps and automating the deployment process, developers can focus more on writing code and less on deployment logistics, leading to improved productivity and project efficiency.

Final Thoughts

We are incredibly excited about this new addition to Visual Studio 2022 and believe it will significantly enhance your development experience. Your continuous feedback is invaluable to us and plays a crucial role in making Visual Studio the best it can be. Thank you for your support, and we look forward to hearing how this feature improves your workflow.

c# – Could not load file or assembly Microsoft.Owin Version=3.0.1.0


execution of my web applications fails with following runtime error:

Could not load file or assembly 'Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Assembly load trace:

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.Owin, Version=3.0.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
 (Fully-specified)
LOG: Appbase = file:///C:/Projects/GIT/Site/Portal/
LOG: Initial PrivatePath = C:\Projects\GIT\Site\Portal\bin
Calling assembly : Microsoft.AspNet.Identity.Owin, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
===

Nowhere in my application do i have a reference to version 3.0.1.0 of Owin. I have no idea where this error is coming from

My packages.config looks like this:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Castle.Core" version="4.2.1" targetFramework="net452" />
  <package id="Crestron.NP.Legacy" version="1.0.7" targetFramework="net471" />
  <package id="Crestron.NP.Legacy.Wrappers.Telerik" version="2024.2.513" targetFramework="net471" />
  <package id="Crestron.NP.System.Enum" version="1.0.3" targetFramework="net452" />
  <package id="Crestron.NP.System.Security" version="2.2.2" targetFramework="net481" />
  <package id="EntityFramework" version="6.4.4" targetFramework="net471" />
  <package id="FluentAssertions" version="4.19.4" targetFramework="net452" />
  <package id="HtmlAgilityPack" version="1.8.5" targetFramework="net452" />
  <package id="jQuery" version="3.7.1" targetFramework="net481" />
  <package id="jQuery.UI.Combined" version="1.13.2" targetFramework="net481" />
  <package id="Microsoft.AspNet.Identity.Core" version="2.2.4" targetFramework="net481" />
  <package id="Microsoft.AspNet.Identity.Owin" version="2.2.4" targetFramework="net481" />
  <package id="Microsoft.AspNet.Razor" version="3.2.5" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebPages" version="3.2.5" targetFramework="net452" />
  <package id="Microsoft.AspNet.WebPages.WebData" version="3.2.4" targetFramework="net452" />
  <package id="Microsoft.CodeDom.Providers.DotNetCompilerPlatform" version="2.0.0" targetFramework="net452" requireReinstallation="true" />
  <package id="Microsoft.Exchange.WebServices" version="2.2" targetFramework="net471" />
  <package id="Microsoft.Extensions.Caching.Abstractions" version="3.1.2" targetFramework="net471" />
  <package id="Microsoft.Extensions.Caching.Memory" version="3.1.2" targetFramework="net471" />
  <package id="Microsoft.Extensions.DependencyInjection.Abstractions" version="3.1.2" targetFramework="net471" />
  <package id="Microsoft.Extensions.Logging.Abstractions" version="3.1.2" targetFramework="net471" />
  <package id="Microsoft.Extensions.Options" version="3.1.2" targetFramework="net471" />
  <package id="Microsoft.Extensions.Primitives" version="3.1.2" targetFramework="net471" />
  <package id="Microsoft.Identity.Client" version="4.37.0" targetFramework="net471" />
  <package id="Microsoft.NETCore.Platforms" version="1.1.0" targetFramework="net471" />
  <package id="Microsoft.Owin" version="4.2.2" targetFramework="net481" />
  <package id="Microsoft.Owin.Host.SystemWeb" version="4.2.2" targetFramework="net481" />
  <package id="Microsoft.Owin.Security" version="4.2.2" targetFramework="net481" />
  <package id="Microsoft.Owin.Security.Cookies" version="4.2.2" targetFramework="net481" />
  <package id="Microsoft.Owin.Security.OAuth" version="4.2.2" targetFramework="net481" />
  <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net452" />
  <package id="NETStandard.Library" version="2.0.3" targetFramework="net481" />
  <package id="Newtonsoft.Json" version="13.0.3" targetFramework="net471" />
  <package id="Owin" version="1.0" targetFramework="net481" />
  <package id="Radius" version="2.0.0.2" targetFramework="net452" />
  <package id="RazorEngine" version="3.10.0" targetFramework="net452" />
  <package id="Syncfusion.Compression.Base" version="27.1.51" targetFramework="net481" />
  <package id="Syncfusion.DocIO.Wpf" version="27.1.51" targetFramework="net481" />
  <package id="Syncfusion.DocToPDFConverter.Wpf" version="27.1.51" targetFramework="net481" />
  <package id="Syncfusion.ExcelToPdfConverter.Wpf" version="27.1.51" targetFramework="net481" />
  <package id="Syncfusion.HtmlToPdfConverter.WPF" version="27.1.51" targetFramework="net481" />
  <package id="Syncfusion.Licensing" version="27.1.51" targetFramework="net481" />
  <package id="Syncfusion.OfficeChart.Base" version="27.1.51" targetFramework="net481" />
  <package id="Syncfusion.Pdf.Wpf" version="27.1.51" targetFramework="net481" />
  <package id="Syncfusion.XlsIO.Wpf" version="27.1.51" targetFramework="net481" />
  <package id="System.Buffers" version="4.4.0" targetFramework="net471" />
  <package id="System.Collections.Immutable" version="1.2.0" targetFramework="net471" />
  <package id="System.ComponentModel.Annotations" version="4.7.0" targetFramework="net471" />
  <package id="System.Linq.Dynamic" version="1.0.7" targetFramework="net452" />
  <package id="System.Memory" version="4.5.2" targetFramework="net471" />
  <package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net471" />
  <package id="System.Reflection.Metadata" version="1.3.0" targetFramework="net471" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.7.0" targetFramework="net471" />
  <package id="System.Text.Encoding.CodePages" version="4.4.0" targetFramework="net471" />
  <package id="System.ValueTuple" version="4.4.0" targetFramework="net45" requireReinstallation="true" />
</packages>

I have already use the clean option in visual studio, deleted the obj and bin folders from my webapp. Error keeps persisting

any ideas?

Keep working with non-blocking Code Cleanup


Are you tired of waiting for Code Cleanup to finish every time you save your work? Visual Studio 2022 will no longer lock up and get in the way of your tasks as it’s cleaning up the code under the covers.

Image async code cleanup on save

Every developer knows the importance of maintaining clean code. However, the traditional Code Cleanup process in Visual Studio could take a while to run and lock up the entire IDE, which made it inappropriate to run on save for all scenarios. These interruptions could break your flow and slow down your development progress.

Now, when you save your work, Code Cleanup can run seamlessly in the background without interrupting your workflow.

With this enhancement enabled, the cleanup process runs quietly in the background without locking up the IDE. This means no more waiting for the cleanup to be completed before resuming your work, whether that’s opening tools or navigating around to different files in your codebase. Your IDE stays fully responsive, ensuring a smoother and more efficient user experience.

Need to make a quick edit, but Code Cleanup started up after you saved? When the editor detects typing, the cleanup process stops. Simply save again to restart cleanup on the updated code. This ensures that you can stay in your workflow and make changes to your code without any worries.

To enable Code Cleanup on save, navigate to Tools > Options > Text Editor > Code Cleanup. Turn on the option Run Code Cleanup profile on Save and choose your desired profile.

Second item in Options window shows checkbox for Run Code Cleanup profile on Save

We continuously strive to enhance your development experience based on your invaluable feedback. These updates to the Code Cleanup feature are a testament to our commitment to making Visual Studio the best it can be. Your insights drive our innovations, and we appreciate your continuous support.

windows – Hyper-V Win11 image faster than physical machine


I started Hyper-V Virtual Machine on my development machine to perform some tests. The virtual machine is running on the same hardware as physical machine. I noticed my application start 2x faster when run on the VM. Both VM and physical machine are Win11 24H2

My first though was that i have problem with my software application and start profiling. I noticed that there is no single method call is faster but every methods calls are significantly faster.

My 2nd though was, probably antivirus software on the physical machine can do that. Check that and both are running MS Defender. Disable/enable doesn’t make a difference.

Then I tried to install all development tools from the physical machine on the VM, because I thought they somehow install some bloatware that can slow down the performance. I did that and the VM is still faster. I tried to perform all the test with VM shuttled down but the physical machine doesn’t get any faster.

Then I noticed it is not only my application. Visual Studio starts faster. I installed also, JetBrains dotTrace and I can see it start faster on the VM to.

What the hell is going on? How is that possible? Any ideas what to check or might cause that mystery? I can’t believe VM can be faster or can it?

It important that I am measuring hot starts of the application. That means i first start the app multiple times before starting the measure the startup time. This is important for the caching of .dll files.

Here some other stuff that might be related:

  1. Bitlocker is turned off on the physical machine
  2. Both machines has developer mode turned on
  3. The physical machine only have a Dev Drive turned on (Note sure if might be related)
  4. Physical machine support hardware virtualization and it is enabled.
  5. CPU is Intel 12th gen
  6. VM runs on 4 cores.

P.S.
I found this: https://community.spiceworks.com/t/vm-hard-disk-speed-much-faster-than-host-disk-speed/603712/16

Virtual Disks are files and as such are kept in host system memory to the extent possible for performance reasons. This translates into very fast benchmarking times and can lead to very long host shutdowns as those disks are flushed back to the physical disks. The virtualization OS (Hyper-V, ESX, Zen, etc.) uses disk caching just like any general purpose OS It then updates the physical disk in background.

c# – Why is my application reading outdated JSON settings and class library changes in Visual Studio?


I’m relatively new to C# and Visual Studio, so I appreciate any guidance.

I have a solution with multiple projects, including:

A WPF project
An ASP.NET project
Several Class Library projects
Several WPF Class Library projects
Additionally, I have a JSON file in the solution that stores settings used across the projects.

The Problem
I updated the value of a setting in the JSON file, specifically the “server” setting from “localhost” to a new value. However, when I run the application, even in debug mode, it continues to read the old value “localhost”.

I’ve also encountered a similar issue with one of the Class Library projects that defines and implements an interface. I made changes to the interface and its implementation, but when the application loads, it seems to use an outdated version of the Class Library. This causes the application to crash, stating that the implementation no longer supports the interface correctly.

What I’ve Tried
Performed “Clean Solution” followed by “Rebuild Solution”.
Deleted all files in:
C:\Users\toto_\AppData\Local\Microsoft\VisualStudio\17.0_ae12b280\Designer\Cache
Verified there are no old versions of the JSON file or the Class Library in the solution directory.
Code Example
For context, here’s the code I use to validate and load the Class Library that implements the interface:

    var assembly = Assembly.LoadFrom(pluginsPath + plugin_.Filename);

    var types = assembly.GetTypes()
    .Where(t => typeof(IPlugin).IsAssignableFrom(t) && !t.IsInterface && !t.IsAbstract);

    foreach (var type in types)
    {
        // The application does not enter this loop
    }

Question:
What steps can I take to ensure that the application reads the updated JSON file and uses the correct version of the Class Library? Could this be a caching issue, or is there something I’m missing in my build process?

Thank you in advance for your help!

visual studio – Error in linking library (undefined reference to)


I am using Visual Studio to remotely build and debug code for my BeagleBoneBlack (BBB). I have connected to it using remote connection session using SSH as in this image –

enter image description here

When I build the code, all the files get copied to my BBB as expected. But when I build the code, I get a bunch of linker errors, particularly for the pthread library.

1>Linking objects
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/BoxMapperII.o: in function `GetNextVial(_VIAL_TAG_&)':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\BoxMapperII.cpp(2529): error : undefined reference to `pthread_mutex_trylock'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/BoxMapperII.o: in function `SetNextVial(_VIAL_TAG_)':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\BoxMapperII.cpp(2551): error : undefined reference to `pthread_mutex_trylock'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/Hardware.o: in function `CHardware::ShutDownMon()':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\Hardware.cpp(333): error : undefined reference to `pthread_create'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/LED_Control.o: in function `CLED_Control::InitLED_Control()':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\LED_Control.cpp(44): error : undefined reference to `pthread_create'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/ListenSocket.o: in function `CListenSocket::Close()':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\ListenSocket.cpp(64): error : undefined reference to `pthread_cancel'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/ListenSocket.cpp:66: undefined reference to `pthread_join'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/ListenSocket.o: in function `CListenSocket::Init(_SERVICE_CONFIG const&)':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\ListenSocket.cpp(186): error : undefined reference to `pthread_create'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/ServerSocket.o: in function `CServerSocket::Close()':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\ServerSocket.cpp(84): error : undefined reference to `pthread_cancel'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/ServerSocket.cpp:87: undefined reference to `pthread_join'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/ServerSocket.o: in function `CServerSocket::Init(unsigned int)':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\ServerSocket.cpp(101): error : undefined reference to `pthread_create'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/UARTCommunication.o: in function `CUARTCommunication::InitUART(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, unsigned int)':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\UARTCommunication.cpp(59): error : undefined reference to `pthread_create'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/UARTCommunication.o: in function `boost::asio::detail::posix_event::posix_event()':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\boost\asio\detail\impl\posix_event.ipp(44): error : undefined reference to `pthread_condattr_setclock'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/UARTCommunication.o: in function `boost::asio::detail::posix_thread::~posix_thread()':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\boost\asio\detail\impl\posix_thread.ipp(35): error : undefined reference to `pthread_detach'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/UARTCommunication.o: in function `boost::asio::detail::posix_thread::join()':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\boost\asio\detail\impl\posix_thread.ipp(42): error : undefined reference to `pthread_join'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/UARTCommunication.o: in function `boost::asio::detail::posix_thread::start_thread(boost::asio::detail::posix_thread::func_base*)':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\boost\asio\detail\impl\posix_thread.ipp(59): error : undefined reference to `pthread_create'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/UARTCommunication.o: in function `boost::asio::detail::posix_signal_blocker::posix_signal_blocker()':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\boost\asio\detail\posix_signal_blocker.hpp(43): error : undefined reference to `pthread_sigmask'
1>/usr/bin/ld : error : /home/debian/projects/BM_II/obj/ARM/Debug/UARTCommunication.o: in function `boost::asio::detail::posix_signal_blocker::~posix_signal_blocker()':
1>C:\Users\ColdSIGHT II\OneDrivem\Documents\BM_II\BM_II\BM_II\boost\asio\detail\posix_signal_blocker.hpp(50): error : undefined reference to `pthread_sigmask'
1>collect2 : error : ld returned 1 exit status
1>Done building project "BM_II.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
========== Build started at 5:13 PM and took 04:56.379 minutes ==========
========== Deploy: 0 succeeded, 0 failed, 0 skipped ==========
========== Deploy started at 5:13 PM and took 04:56.379 minutes ==========  

I see that my pthread.h is located in the local folder – C:\Users\ColdSIGHTII\AppData\Local\Microsoft\Linux\HeaderCache\1.0\-689744971\usr\include\linux. I don’t understand why pthead.h is the only library that is not linked. There are other libraries such as stdio.h that my source code uses and they are located in the same folder as well.But they do not give the linker errors. Please let me know what I am doing wrong. Thank you.

Edit – My configuration for linker looks like this –

enter image description here

visual studio – How do I obtain timing in a CUDA c++ kernel?


I finally created a GPU powered low md5-finder, I am so happy! Here is the code, slightly adapted form another implementation:

https://github.com/EnesO226/md5zerofinder/blob/main/kernel.cu

However, when I try to use cudaEvents in the kernel, my visual studio says that cudaEvents are not allowed in a kernel. I want to print the hashrate here, everytime a new hash is found:

__device__ void md5(const uchar* data, const uint size, uint result[4])
{
    uint state[4] = { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476 }, i;

    for (i = 0; i + block_size <= size; i += block_size)
    {
        transform(state, data + i);
    }

    uint size_in_bits = size << 3;
    uchar buffer[block_size];

    memcpy(buffer, data + i, size - i);
    memcpy(buffer + size - i, padding, block_size - (size - i));
    memcpy(buffer + block_size - (2 * sizeof(uint)), &size_in_bits, sizeof(uint));

    transform(state, buffer);

    memcpy(result, state, 4 * sizeof(uint));
    if (result[0] == 0 && byteswap(result[1]) < 0x0fffffff) {
        printf("Hash found -------> %08x%08x%08x%08x\n", byteswap(result[0]), byteswap(result[1]), byteswap(result[2]), byteswap(result[3]));
        printf("For data   -------> ");
        for (int j = 0; j < size; j++) {
            printf("%02x", data[j]);
        }
        printf("\n\n");

    }
}

And the kernel which is actually run is this:

__global__ void test() {
    int thread = blockIdx.x * blockDim.x + threadIdx.x;
    uchar m[12];
    uint res[4];
    m[0] = (uchar)(thread & 0x000000ff);
    m[1] = (uchar)((thread >> 8) & 0x000000ff);
    m[2] = (uchar)((thread >> 16) & 0x000000ff);
    m[3] = (uchar)((thread >> 24) & 0x000000ff);

    for (unsigned long long i = 0; i < 0xffffffffffffffff; i++) {
        m[4] = (uchar)(i & 0x000000ff);
        m[5] = (uchar)((i >> 8) & 0x00000000000000ff);
        m[6] = (uchar)((i >> 16) & 0x00000000000000ff);
        m[7] = (uchar)((i >> 24) & 0x00000000000000ff);
        m[8] = (uchar)((i >> 32) & 0x00000000000000ff);
        m[9] = (uchar)((i >> 40) & 0x00000000000000ff);
        m[10] = (uchar)((i >> 48) & 0x00000000000000ff);
        m[11] = (uchar)((i >> 56) & 0x00000000000000ff);
        md5(m, 12, res);
    }
}

int main()
{
    test << <1024, 1024 >> > ();
    system("pause");
    return 0;
}

How would I go about getting the hashrate here? I asked google (and chatGPT, yes, it is useful sometimes) but I only know how to time the timing when the kernel is already finished, so I would have to set the iterations way lower, but then it does not run indefinitely, you understand? So that is my question; is there a way to get timing in a cuda __device__ or __global__ kernel?

IMPORTANT: my visual studio does not support atomicAdd and clock()

c# – Visual Studio 2022 not showing unit tests by group


I am new to unit testing and have set a bunch up. I wanted to be able to group them so I can run tests based on group if necessary. I have set up a few of my test methods like this based on a Microsoft article:

 [TestMethod, TestCategory("ReCaptcha")]
 public async Task TestValidateGoogleReCaptcha_NullResponse(){
   // some code here
}

I have done this on 3 test methods and selected the group by “traits” in the group by drop down. The others I have no TestCategory. It says all of my test have no traits

enter image description here

I cannot figure out what I am missing. Does anyone have the same issue and a possible fix?
Thank you

Introducing Code Referencing for GitHub Copilot Chat in Visual Studio


Are you tired of the uncertainty that comes with using code suggestions from AI tools? We’ve got exciting news for you! Visual Studio 2022 now includes code referencing in GitHub Copilot, ensuring greater transparency and control for developers.

We are thrilled to announce that code referencing is now available in GitHub Copilot Chat within Visual Studio. This new feature introduces a filter that detects when code suggestions match public code on GitHub, providing you with valuable context to make more informed decisions about the code you incorporate into your projects.

Make Informed Decisions with Code Suggestions

In the rare instances where GitHub Copilot suggests code that matches public repositories on GitHub, this feature displays a list of those repositories along with their licenses directly in the editor. This transparency empowers you to:

  • Learn from existing implementations: Gain insights from how others have tackled similar problems.
  • Consider dependencies: Decide whether to use an existing library instead of writing new code.
  • Acknowledge similar work: Give or receive credit for comparable code within the community.

How It Works

When GitHub Copilot suggests code that matches public code, it now lets you know of this match. You can view the matching code, its source file, and any associated licensing information directly within Visual Studio. This allows you to make more informed decisions about whether to use the suggested code.

If a match is found, a notification appears in the editor showing:

  1. The matching code snippet
  2. Repositories where the code appears
  3. The licenses governing each repository

You have the option to block suggestions containing matching code or allow them with full awareness of their context.

In Copilot Chat it will show like this

Highlighting that copilot found similar code in git repos with the option to view

Instead of this:

Original error showing that the response matched public code so it was blcoked

Try It Out Today

We believe this new code referencing feature enhances your development experience by adding an extra layer of transparency and choice. Try it out in Visual Studio 17.12 Preview 3 and above, and let us know your feedback. Your insights help us improve and tailor our tools to better meet your needs.

Configuration Note

Please note that this feature may need to be configured by your administrator. To ensure its enabled for you, check your settings:

  • Copilot – Suggestions matching public code (duplication detection filter): Allowed

GitHub Copilot can provide you with details about matching code when you accept such suggestions. Learn more.

Enabling or Disabling Suggestions Matching Public Code

Note: If you are a member of an organization on GitHub Enterprise Cloud and have been assigned a GitHub Copilot seat through your organization, you may not be able to configure suggestions matching public code in your personal account settings. Your settings will be inherited from your organization or enterprise.

Your personal settings for GitHub Copilot include an option to either allow or block code suggestions that match publicly available code:

  • Block suggestions matching public code: GitHub Copilot checks code suggestions with their surrounding code against public code on GitHub. If there’s a match or near match, the suggestion is not shown.
  • Allow suggestions matching public code: When Copilot suggests matching code, you can view details of the matches and navigate to the relevant repositories on GitHub.

To adjust your settings:

  1. In the upper-right corner of any page on GitHub, click your profile photo, then click Your Copilot.
  2. Next to Suggestions matching public code, use the dropdown menu to select Allow or Block.

For more information, see Managing Copilot policies as an individual subscriber.

Developers often face the challenge of not knowing the origins of code suggestions offered by AI tools. This can lead to concerns about licensing and the appropriateness of using certain code snippets. With the new code referencing feature in GitHub Copilot, those worries are outdated.

Fostering knowledge sharing

By integrating code referencing into GitHub Copilot, we are fostering a culture of knowledge sharing and transparency. This feature not only empowers individual developers but also supports larger teams in navigating the complexities of public code with ease.